//============================================================================================
/**
 * @file	fd_shop.c
 * @brief	フレンドリィショップ処理
 * @author	Hiroyuki Nakamura
 * @date	2004.12.15
 */
//============================================================================================

// ショップ画面でカメラ使用のスクロールをしない定義
#define NO_SHOP_SCROLL

// プレミアボールの流れが動く
#define SHOP_PREMIUM_BALL

// 有効にするとポケスロンショップを開くたびにポイントを１０００追加される
//#define DEBUG_POKETHLON_ADD_POINT

#include "common.h"
#include "system/procsys.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/fontproc.h"
#include "system/msgdata.h"
#include "system/wordset.h"
#include "system/buflen.h"
#include "system/arc_tool.h"
#include "system/arc_util.h"
#include "system/snd_tool.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/render_oam.h"
#include "system/wipe.h"
#include "gflib/touchpanel.h"
#include "itemtool/item.h"
#include "itemtool/myitem.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_shop.h"
#include "msgdata/msg_undergroundgoods.h"
#include "msgdata/msg_place_name.h"
#include "application/app_tool.h"
#include "application/bag.h"
#include "seal/seal.h"

#include "fieldsys.h"
#include "fieldmap.h"
#include "field_clact.h"
#include "fld_bmp.h"
#include "field_poketch.h"
#include "talk_msg.h"
#include "syswork.h"
#include "zonedata.h"
#include "mapdefine.h"
#include "sysflag.h"

///#include "goods_data.h"
///#include "../fielddata/base_goods/goods_id_def.h"
#include "data/clact_util/clact_header.naix"
#include "savedata/record.h"

#define	FD_SHOP_H_GLOBAL
#include "fd_shop_sys.h"
#include "fd_shop.h"
#include "fd_shop_snd_def.h"
#include "shop_gra.naix"

#include "fld_debug.h"		//DEBUG_VIEW_HOOK


//============================================================================================
//	定数定義
//============================================================================================
// BGフレーム
#define	SHOP_FRM_3D			( FLD_MBGFRM_MAP )		// 3D面
#define	SHOP_FRM_BG			( FLD_MBGFRM_EFFECT1 )	// 枠
#define	SHOP_FRM_LIST		( FLD_MBGFRM_EFFECT2 )	// アイテムリスト
#define	SHOP_FRM_WINDOW		( FLD_MBGFRM_FONT )		// ウィンドウ面
#define	SHOP_BG_PAL			( 0 )

#define	SHOP_TALK_WIN_CGX	( 1 )
#define	SHOP_MENU_WIN_CGX	( SHOP_TALK_WIN_CGX + TALK_WIN_CGX_SIZ )

// BMPウィンドウ定義
// ショップメニュー（フィールドの領域に注意！）
/*
#define	WIN_SHOP_MENU_PX	( 1 )
#define	WIN_SHOP_MENU_PY	( 1 )
#define	WIN_SHOP_MENU_SX	( 13 )
#define	WIN_SHOP_MENU_SY	( 6 )		// アイテムショップ
#define	WIN_SHOP_MENU_SY_GS	( 4 )		// グッズ・シールショップ
#define	WIN_SHOP_MENU_PAL	( FLD_SYSFONT_PAL )
#define	WIN_SHOP_MENU_CGX	( FLD_MSG_WIN_CGX - ( WIN_SHOP_MENU_SX * WIN_SHOP_MENU_SY ) )
*/
// アイテムリスト
#define	WIN_SHOP_LIST_PX	( 13 )
#define	WIN_SHOP_LIST_PY	( 2 )
#define	WIN_SHOP_LIST_SX	( 18 )
#define	WIN_SHOP_LIST_SY	( 14 )
#define	WIN_SHOP_LIST_FRM	( SHOP_FRM_LIST )
#define	WIN_SHOP_LIST_PAL	( FLD_SYSFONT_PAL )
//#define	WIN_SHOP_LIST_CGX	( SHOP_MENU_WIN_CGX - ( WIN_SHOP_LIST_SX * WIN_SHOP_LIST_SY ) )
#define	WIN_SHOP_LIST_CGX	( 1 )
// アイテム説明
#define	WIN_SHOP_INFO_PX	( 5 )		// アイテムショップ
#define	WIN_SHOP_INFO_PX_GS	( 1 )		// グッズ・シールショップ
#define	WIN_SHOP_INFO_PY	( 18 )
#define	WIN_SHOP_INFO_SX	( 27 )
#define	WIN_SHOP_INFO_SY	( 6 )
#define	WIN_SHOP_INFO_FRM	( SHOP_FRM_LIST )
#define	WIN_SHOP_INFO_PAL	( FLD_SYSFONT_PAL )
//#define	WIN_SHOP_INFO_CGX	( WIN_SHOP_LIST_CGX - ( WIN_SHOP_INFO_SX * WIN_SHOP_INFO_SY ) )
#define	WIN_SHOP_INFO_CGX	( WIN_SHOP_LIST_CGX + ( WIN_SHOP_LIST_SX * WIN_SHOP_LIST_SY ) )

// おこずかい
#define	WIN_SHOP_GOLD_PX	( 1 )
#define	WIN_SHOP_GOLD_PY	( 1 )
#define	WIN_SHOP_GOLD_SX	( 10 )
#define	WIN_SHOP_GOLD_SY	( 4 )
#define	WIN_SHOP_GOLD_FRM	( SHOP_FRM_WINDOW )
#define	WIN_SHOP_GOLD_PAL	( FLD_SYSFONT_PAL )
//#define	WIN_SHOP_GOLD_CGX	( WIN_SHOP_INFO_CGX - ( WIN_SHOP_GOLD_SX * WIN_SHOP_GOLD_SY ) )
#define	WIN_SHOP_GOLD_CGX	( SHOP_MENU_WIN_CGX + MENU_WIN_CGX_SIZ )
// 個数選択
#define	WIN_SHOP_NUM_PX		( 19 )
#define	WIN_SHOP_NUM_PY		( 13 )
#define	WIN_SHOP_NUM_SX		( 12 )
#define	WIN_SHOP_NUM_SY		( 4 )
#define	WIN_SHOP_NUM_FRM	( SHOP_FRM_WINDOW )
#define	WIN_SHOP_NUM_PAL	( FLD_SYSFONT_PAL )
//#define	WIN_SHOP_NUM_CGX	( WIN_SHOP_GOLD_CGX - ( WIN_SHOP_NUM_SX * WIN_SHOP_NUM_SY ) )
#define	WIN_SHOP_NUM_CGX	( WIN_SHOP_GOLD_CGX + ( WIN_SHOP_GOLD_SX * WIN_SHOP_GOLD_SY ) )
// 持っている数
#define	WIN_SHOP_MINE_PX	( 1 )
#define	WIN_SHOP_MINE_PY	( 15 )
#define	WIN_SHOP_MINE_SX	( 14 )
#define	WIN_SHOP_MINE_SY	( 2 )
#define	WIN_SHOP_MINE_FRM	( SHOP_FRM_WINDOW )
#define	WIN_SHOP_MINE_PAL	( FLD_SYSFONT_PAL )
//#define	WIN_SHOP_MINE_CGX	( WIN_SHOP_NUM_CGX - ( WIN_SHOP_MINE_SX * WIN_SHOP_MINE_SY ) )
#define	WIN_SHOP_MINE_CGX	( WIN_SHOP_NUM_CGX + ( WIN_SHOP_NUM_SX * WIN_SHOP_NUM_SY ) )
// 会話
#define	WIN_SHOP_TALK_PX	( 2 )
#define	WIN_SHOP_TALK_PY	( 19 )
#define	WIN_SHOP_TALK_SX	( 27 )
#define	WIN_SHOP_TALK_SY	( 4 )
#define	WIN_SHOP_TALK_FRM	( SHOP_FRM_WINDOW )
#define	WIN_SHOP_TALK_PAL	( FLD_MESFONT_PAL )
//#define	WIN_SHOP_TALK_CGX	( WIN_SHOP_MINE_CGX - ( WIN_SHOP_TALK_SX * WIN_SHOP_TALK_SY ) )
#define	WIN_SHOP_TALK_CGX	( WIN_SHOP_MINE_CGX + ( WIN_SHOP_MINE_SX * WIN_SHOP_MINE_SY ) )
// はい・いいえ
#define	WIN_SHOP_YESNO_PX	( 23 )
#define	WIN_SHOP_YESNO_PY	( 13 )
#define	WIN_SHOP_YESNO_SX	( 7 )
#define	WIN_SHOP_YESNO_SY	( 4 )
#define	WIN_SHOP_YESNO_FRM	( SHOP_FRM_WINDOW )
#define	WIN_SHOP_YESNO_PAL	( FLD_SYSFONT_PAL )
//#define	WIN_SHOP_YESNO_CGX	( WIN_SHOP_TALK_CGX - ( WIN_SHOP_YESNO_SX * WIN_SHOP_YESNO_SY ) )
#define	WIN_SHOP_YESNO_CGX	( WIN_SHOP_TALK_CGX + ( WIN_SHOP_TALK_SX * WIN_SHOP_TALK_SY ) )

#define	SHOPCOL_N_BLACK	( GF_PRINTCOLOR_MAKE( 1, 2, 0 ) )		// フォントカラー：黒
#define	SHOPCOL_N_WHITE	( GF_PRINTCOLOR_MAKE( 15, 14, 0 ) )		// フォントカラー：白
#define	SHOPCOL_N_BLUE	( GF_PRINTCOLOR_MAKE( 3, 4, 0 ) )		// フォントカラー：青
#define	SHOPCOL_N_RED	( GF_PRINTCOLOR_MAKE( 5, 6, 0 ) )		// フォントカラー：赤

#define	MSG_BUFLEN		( 24*2*2 )


#define	CURSOR_ACT_PX	( 176 )
#define	CURSOR_ACT_PY	( 24 )


typedef struct{
	u8 x,y;
	u8 anim;
	u8 pal;
}SHOP_CURSOR_INFO;

static const SHOP_CURSOR_INFO shop_cursor_pos[]={
	{48,    56,       0, 7,},	// ６つのアイテムアイコン
	{48+128,56,       0, 7,},
	{48,    56+32+8,  0, 7,},
	{48+128,56+32+8,  0, 7,},
	{48,    56+64+16, 0, 7,},
	{48+128,56+64+16, 0, 7,},

	{8*3,   176,	 4,	7,},	// 上矢印
	{40+8*3,176,	 4,	7,},	// 下矢印
	{224,   176,	 7,	7,},	// やめる

	{ 160,   176, 	 7, 7,},	// かう


};


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
#ifndef NO_SHOP_SCROLL
static   u8 CameraMoveCntGet( FIELDSYS_WORK * fsys );
#endif	// NO_SHOP_SCROLL
static   u8 ShopEndSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk );
static void ShopInitSeq( SHOP_WORK * wk );
static void ShopMsgCreate( SHOP_WORK * wk );
//static void ShopMenuSet( SHOP_WORK * wk );
//static   u8 ShopMenuSelect( SHOP_WORK * wk );
static   u8 ShopTouchSelect( SHOP_WORK *wk, u32 arret );
//static void ShopMenuExit( SHOP_WORK * wk );
static void ShopBuyInitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk );
static void ShopBuyWinAdd( SHOP_WORK * wk );
static void ShopBuyGraphicSet( SHOP_WORK * wk );
static   u8 ShopBuyScrollSeq( FIELDSYS_WORK *fsys, SHOP_WORK * wk );
static   u8 ShopBuySelectSeq( SHOP_WORK * wk );
static   u8 ShopBuyEndSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk );
//static void ShopBuyItemListMake( SHOP_WORK * wk );
//static void CB_ItemListMove( BMPLIST_WORK * work, u32 param, u8 mode );
//static void CB_ItemListWrite( BMPLIST_WORK * work, u32 param, u8 y );
//static void ShopBuyGoldWinPut( SHOP_WORK * wk, u8 flg );
static   u8 ShopBuySelWaitSeq( SHOP_WORK * wk );
static   u8 ShopBuyNumSelSeq( SHOP_WORK * wk );
//static void NumSelWinPut( SHOP_WORK * wk, u8 flg );
//static void MyItemWinPut( SHOP_WORK * wk );
static   u8 ShopBuyCmpWaitSeq( SHOP_WORK * wk );
static   u8 ShopBuyOmakeWait( SHOP_WORK * wk );
static   u8 ShopBuyNumWaitSeq( SHOP_WORK * wk );
static   u8 ShopBuyYesNoSeq( SHOP_WORK * wk, u32 arret );
static   u8 ShopBuyCmpSeq( SHOP_WORK * wk );
//static   u8 ShopBuyMenuRetSeq( SHOP_WORK * wk );
static   u8 ShopBuyCantWaitSeq( SHOP_WORK * wk );
//static void ShopExitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk );
static void ShopSaleInitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk );
static void ShopSaleCallSeq( GMEVENT_CONTROL * event );
//static u8 ShopSaleWaitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk );
//static u8 ShopSaleRetSeq( FIELDSYS_WORK * fsys );
static   u8 ShopSaleMenuRetSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk );

static   u8 ShopBuyNumTouchSelSeq( SHOP_WORK *wk, u32 arret );

static void ShopBuyActExit( SHOP_WORK * wk );
static void load2DResFile( SHOP_WORK * wk );
static  int loadOneData(
			CLACT_U_RES_MANAGER_PTR resMan, CLACT_U_RES_OBJ_TBL** resObjTbl, const char* path );

static void ShopBuyScrCurPosChg( SHOP_WORK * wk, u8 flg );

static void ShopBuyItemIconChg( SHOP_WORK * wk, u16 item );
static void ShopBuySubLCDItemIconChg( SHOP_WORK * wk, int charaId, int palId, u16 item );
static void ShopBuyCursorPalChg( SHOP_WORK * wk, u8 num );

static   u8 ShopBuyCmpCheck( SHOP_WORK * wk );

static void ShopBuySublcdEnd(FIELDSYS_WORK * fsys, SHOP_WORK * wk );
static  int ShopDecideFunc( SHOP_WORK *wk, int decide );
static   u8 ShopCancelFunc( SHOP_WORK *wk );
static void ShopCursorActPosSet( SHOP_WORK *wk, int pos, int mode );
static void ShopItemIconPageChange( SHOP_WORK * wk, int scr, int max );
static   u8 ShopBuyNumDecide( SHOP_WORK *wk );
static   u8 ShopBuyNumCancel( SHOP_WORK *wk );
static   u8 ShopBuyNumTouchSelSeq( SHOP_WORK *wk, u32 arret );
static void ShopBuyItemInfoChange( SHOP_WORK *wk, int pos );

static  int _get_item_max( u16 *item, const PS_SHOP_DATA *psitem, int type );
static void _set_item_data( SHOP_WORK *wk, u16 *item, int ball_flag );
static void _set_psitem_data( SHOP_WORK *wk, const PS_SHOP_DATA *psitem );
static  u32 _get_gold_point( SHOP_WORK *wk, int type );
static void _sub_gold_point( SHOP_WORK *wk, int price );
static void _add_pokethlon_shop( SHOP_WORK *wk, int item );

static void ShopBgPriorityReset( SHOP_WORK * wk );

static u8 ShopBuyPageSub( SHOP_WORK * wk );
static u8 ShopBuyPageAdd( SHOP_WORK * wk );

static u8 ButtonAnmSet( SHOP_WORK * wk, u8 id, u8 next );
static u8 ButtonAnmMain( SHOP_WORK * wk );

static int ItemNumMove( int num, int max, int move );


//============================================================================================
//	グローバル変数
//============================================================================================
static const BMPWIN_DAT ShopBuyBmpWin[] =
{
	{	// アイテムリスト
		WIN_SHOP_LIST_FRM, WIN_SHOP_LIST_PX, WIN_SHOP_LIST_PY,
		WIN_SHOP_LIST_SX, WIN_SHOP_LIST_SY, WIN_SHOP_LIST_PAL, WIN_SHOP_LIST_CGX
	},
	{	// アイテム説明
		WIN_SHOP_INFO_FRM, WIN_SHOP_INFO_PX, WIN_SHOP_INFO_PY,
		WIN_SHOP_INFO_SX, WIN_SHOP_INFO_SY, WIN_SHOP_INFO_PAL, WIN_SHOP_INFO_CGX
	},
	{	// おこずかい
		WIN_SHOP_GOLD_FRM, WIN_SHOP_GOLD_PX, WIN_SHOP_GOLD_PY,
		WIN_SHOP_GOLD_SX, WIN_SHOP_GOLD_SY, WIN_SHOP_GOLD_PAL, WIN_SHOP_GOLD_CGX
	},
	{	// 個数選択
		WIN_SHOP_NUM_FRM, WIN_SHOP_NUM_PX, WIN_SHOP_NUM_PY,
		WIN_SHOP_NUM_SX, WIN_SHOP_NUM_SY, WIN_SHOP_NUM_PAL, WIN_SHOP_NUM_CGX
	},
	{	// 持っている数
		WIN_SHOP_MINE_FRM, WIN_SHOP_MINE_PX, WIN_SHOP_MINE_PY,
		WIN_SHOP_MINE_SX, WIN_SHOP_MINE_SY, WIN_SHOP_MINE_PAL, WIN_SHOP_MINE_CGX
	},
	{	// 会話
		WIN_SHOP_TALK_FRM, WIN_SHOP_TALK_PX, WIN_SHOP_TALK_PY,
		WIN_SHOP_TALK_SX, WIN_SHOP_TALK_SY, WIN_SHOP_TALK_PAL, WIN_SHOP_TALK_CGX
	},
};

// グッズ・シールの説明
static const BMPWIN_DAT ShopBuyGoodsInfoWin = {
	WIN_SHOP_INFO_FRM, WIN_SHOP_INFO_PX_GS, WIN_SHOP_INFO_PY,
	WIN_SHOP_INFO_SX, WIN_SHOP_INFO_SY, WIN_SHOP_INFO_PAL, WIN_SHOP_INFO_CGX
};

/*
// はい・いいえ
static const BMPWIN_DAT ShopBuyYesNoBmpWin = {
	WIN_SHOP_YESNO_FRM, WIN_SHOP_YESNO_PX, WIN_SHOP_YESNO_PY,
	WIN_SHOP_YESNO_SX, WIN_SHOP_YESNO_SY, WIN_SHOP_YESNO_PAL, WIN_SHOP_YESNO_CGX
};
*/

// バッグのポケットリスト
static const u8 BagList[] = {
	BAG_POKE_NORMAL, BAG_POKE_DRUG, BAG_POKE_BALL, BAG_POKE_WAZA,
	BAG_POKE_NUTS, BAG_POKE_SEAL, BAG_POKE_BATTLE, BAG_POKE_EVENT, 0xff
};


#define SHOP_ITEM_MAX	( 256 )
#define SHOP_END_DATA	( 0xffff )


//============================================================================================
//	購入画面のセルアクター用定義
//============================================================================================
// リソースID
enum {
	CLA_ID_ARROW = 0,
	CLA_ID_CURSOR,
	CLA_ID_M_ITEMICON,
	CLA_ID_S_ITEMICON0,
	CLA_ID_S_ITEMICON1,
	CLA_ID_S_ITEMICON2,
	CLA_ID_S_ITEMICON3,
	CLA_ID_S_ITEMICON4,
	CLA_ID_S_ITEMICON5,
	CLA_ID_S_INTERFACE,
};


#define	LIST_SCR_PX		( 177 )
#define	LIST_SCR_U_PY	( 8 )
#define	LIST_SCR_D_PY	( 132 )

#define	NUM_SCR_PX		( 162 )
#define	NUM_SCR_U_PY	( 108 )
#define	NUM_SCR_D_PY	( 132 )

#define	SHOP_ITEMICON_PX	( 22 )
#define	SHOP_ITEMICON_PY	( 172 )

// 選択時のどうぐアイコンの座標
#define SELECT_ITEM_ICON_POS_X	( 86 )
#define SELECT_ITEM_ICON_POS_Y	( 76 )


///TCATS_RES_ARC
#define SHOP_S_ITEMICON0_PX		( 22 )
#define SHOP_S_ITEMICON0_PY		( 59 )
#define SHOP_S_ITEMICON1_PX		( 152 )
#define SHOP_S_ITEMICON1_PY		( 59  )
#define SHOP_S_ITEMICON2_PX		( 22  )
#define SHOP_S_ITEMICON2_PY		( 100 )
#define SHOP_S_ITEMICON3_PX		( 152 )
#define SHOP_S_ITEMICON3_PY		( 100 )
#define SHOP_S_ITEMICON4_PX		( 22  )
#define SHOP_S_ITEMICON4_PY		( 139 )
#define SHOP_S_ITEMICON5_PX		( 152 )
#define SHOP_S_ITEMICON5_PY		( 139 )


static const TCATS_RESOURCE_FILE_LIST CatsFileList = {
	NARC_clact_header_shop_chr_resdat,	// キャラクタ
	NARC_clact_header_shop_pal_resdat,	// パレット
	NARC_clact_header_shop_cell_resdat,	// セル
	NARC_clact_header_shop_canm_resdat,	// セルアニメ
	TCATS_RESID_NULL,					// マルチセル
	TCATS_RESID_NULL,					// マルチセルアニメ
	NARC_clact_header_shop_h_cldat		// ヘッダー

};

static const TCATS_OBJECT_ADD_PARAM	ActAddParam[] =
{
	{	// 上矢印カーソル
		CLA_ID_ARROW,
		LIST_SCR_PX, LIST_SCR_U_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		0, 0, 0, 0
	},
	{	// 下矢印カーソル
		CLA_ID_ARROW,
		LIST_SCR_PX, LIST_SCR_D_PY, 0,
		1, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		0, 0, 0, 0
	},
	{	// カーソル
		CLA_ID_CURSOR,
		CURSOR_ACT_PX, CURSOR_ACT_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		0, 0, 0, 0
	},
	{	// アイテムアイコン
		CLA_ID_M_ITEMICON,
		SHOP_ITEMICON_PX, SHOP_ITEMICON_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		0, 0, 0, 0
	},
	{	// アイテムアイコン（下画面0番目）
		CLA_ID_S_ITEMICON0,
		SHOP_S_ITEMICON0_PX, SHOP_S_ITEMICON0_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// アイテムアイコン（下画面1番目）
		CLA_ID_S_ITEMICON1,
		SHOP_S_ITEMICON1_PX, SHOP_S_ITEMICON1_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// アイテムアイコン（下画面2番目）
		CLA_ID_S_ITEMICON2,
		SHOP_S_ITEMICON2_PX, SHOP_S_ITEMICON2_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// アイテムアイコン（下画面3番目）
		CLA_ID_S_ITEMICON3,
		SHOP_S_ITEMICON3_PX, SHOP_S_ITEMICON3_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// アイテムアイコン（下画面4番目）
		CLA_ID_S_ITEMICON4,
		SHOP_S_ITEMICON4_PX, SHOP_S_ITEMICON4_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// アイテムアイコン（下画面5番目）
		CLA_ID_S_ITEMICON5,
		SHOP_S_ITEMICON5_PX, SHOP_S_ITEMICON5_PY, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},

	// 10
	{	// カーソル（下画面）
		CLA_ID_S_INTERFACE,
		0, 0, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},

	{	// ページ上矢印（下画面）
		CLA_ID_S_INTERFACE,
		8*3, 176, 0,
		2, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},

	{	// ページ下矢印（下画面）
		CLA_ID_S_INTERFACE,
		40+8*3, 176, 0,
		3, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},

	{	// やめる（下画面）
		CLA_ID_S_INTERFACE,
		224, 176, 0,
		6, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},

	{	// 売る・捨てる時の上矢印パネル0
		CLA_ID_S_INTERFACE,
		136, 104, 0,
		12, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// 売る・捨てる時の上矢印パネル1
		CLA_ID_S_INTERFACE,
		136+32, 104, 0,
		12, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// 売る・捨てる時の下矢印パネル0
		CLA_ID_S_INTERFACE,
		136, 152, 0,
		14, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},
	{	// 売る・捨てる時の下矢印パネル1
		CLA_ID_S_INTERFACE,
		136+32, 152, 0,
		14, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},

	{	// 「かう」ボタン
		CLA_ID_S_INTERFACE,
		160, 192-16, 0,
		24, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		0, 0, 0, 0
	},

};


//------------------------------------------------------------------
/**
 * @brief   どうぐの総数を数える（通常・ポケスロン対応）
 *
 * @param   item
 * @param   psitem
 * @param   type
 *
 * @retval  int
 */
//------------------------------------------------------------------
static int _get_item_max( u16 *item, const PS_SHOP_DATA *psitem, int type )
{
	int i;
	if( type==SHOP_TYPE_POKETHLON || type==SHOP_TYPE_POKETHLON_CARD){
		// ポケスロンショップアイテム最大数取得
		for( i=0; i<SHOP_ITEM_MAX; i++ ){
			if( psitem[i].item == SHOP_END_DATA ){ break; }
		}
	}else{
		// どうぐ最大数取得
		for( i=0; i<SHOP_ITEM_MAX; i++ ){
			if( item[i] == SHOP_END_DATA ){ break; }
		}
	}
	return i;
}

//------------------------------------------------------------------
/**
 * @brief   どうぐリストをショップワークに登録（通常アイテム）
 *
 * @param   wk
 * @param   item
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void _set_item_data( SHOP_WORK *wk, u16 *item, int ball_flag )
{
	int i,count=0,max;

	max = wk->max;
	for( i=0; i<max; i++ ){
		if(ball_flag==0){
			// ボールフラグが０ならモンスターボールを登録しない
			if(item[i]==ITEM_MONSUTAABOORU){
				// ボールを登録せず最大数を１減らす
				wk->max--;
			}else{
				wk->item[count] = item[i];
				count++;
			}
		}else{
			// ボールフラグが１なら普通にリスト追加
			wk->item[count] = item[i];
			count++;
		}
	}

}

//------------------------------------------------------------------
/**
 * @brief   ポケスロンショップリストをどうぐワークに登録
 *
 * @param   wk
 * @param   psitem
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void _set_psitem_data( SHOP_WORK *wk, const PS_SHOP_DATA *psitem )
{
	int i,count=0;
	for( i=0; i<wk->max; i++ ){
		wk->item[count] = psitem[i].item;
		count++;
	}

}


//--------------------------------------------------------------------------------------------
/**
 * アイテムデータをショップワークにセット
 *
 * @param	wk			ショップワーク
 * @param	item		アイテムデータ
 * @param	ball_flag	モンスターボールを追加するかどうか（0:しない 1:する）
 * @param   psitem		ポケスロンアイテムデータ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopItemSet( SHOP_WORK * wk, u16 * item, int ball_flag, const PS_SHOP_DATA *psitem )
{
	int	count=0;

	MORI_PRINT("monsball = %d\n", ball_flag);

	// どうぐ総数取得
	wk->max = _get_item_max( item, psitem, wk->shop_type );

	// ちゃんとアイテムデータが読み込めてる？
	GF_ASSERT( wk->max < (SHOP_ITEM_MAX-1) )

	// 購入どうぐ配列確保
	wk->item = sys_AllocMemory( HEAPID_WORLD, wk->max*2 );
	if( wk->shop_type==SHOP_TYPE_POKETHLON || wk->shop_type==SHOP_TYPE_POKETHLON_CARD){
		// ポケスロンアイテム登録
		_set_psitem_data( wk, psitem );
#ifdef DEBUG_POKETHLON_ADD_POINT
		PkthlnSv_AddThlnPoint (wk->pokethlon_save, 10000 );
#endif
	}else{
		// 通常のアイテム登録
		_set_item_data( wk, item, ball_flag );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ショップワーク確保
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static SHOP_WORK * ShopWorkAlloc(void)
{
	SHOP_WORK * wk = sys_AllocMemory( HEAPID_WORLD, sizeof(SHOP_WORK) );
	memset( wk, 0, sizeof(SHOP_WORK) );
	return wk;
}

/*
static void _pokethlon_flag_get( SHOP_WORK *wk )
{


}
*/

//--------------------------------------------------------------------------------------------
/**
 * ショップ呼び出し
 *
 * @param	event	イベント
 * @param	repw	フィールドワーク
 * @param	item	商品テーブル
 * @param	type	ショップタイプ
 * @param	mode	0 = 買う、1 = 売る
 * @param	dp_flg	デパートフラグ
 * @param   data    ポケスロンショップデータ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ShopInit( GMEVENT_CONTROL * event, FIELDSYS_WORK * repw, u16 * item, u8 type, u8 mode, BOOL dp_flg, const PS_SHOP_DATA *psitem)
{
	SHOP_WORK * wk = ShopWorkAlloc();
	int i;

	wk->bgl    = repw->bgl;
	wk->msgb   = STRBUF_Create( MSG_BUFLEN, HEAPID_WORLD );
	wk->my     = SaveData_GetMyStatus( repw->savedata );
	wk->cfg    = SaveData_GetConfig( repw->savedata );
	wk->rec    = SaveData_GetRecord( repw->savedata );
	wk->evwk   = SaveData_GetEventWork( repw->savedata );
	wk->bonguri = SaveData_GetBonguriSave( repw->savedata );
	wk->dp_flg = dp_flg;
#ifndef NO_SHOP_SCROLL
	wk->cm_max = CameraMoveCntGet( repw );
#endif	// NO_SHOP_SCROLL
	wk->shop_type      = type;
	wk->scr			   = 0;
	wk->cursor_pos     = 0;
	wk->touch_arret    = SHOP_TOUCHCODE_NONE;
	wk->sublcd_refresh = SUBLCD_NO_REFRESH;
	wk->pokethlon_save = PkthlnSv_GetSaveData(repw->savedata);
	wk->psitem         = psitem;
	wk->mode           = mode;

	if( wk->shop_type == SHOP_TYPE_ITEM || wk->shop_type == SHOP_TYPE_POKETHLON || wk->shop_type == SHOP_TYPE_POKETHLON_CARD){
		wk->myitem = SaveData_GetMyItem( repw->savedata );
	}else{
		wk->myitem = CB_SaveData_AllDataGet( repw->savedata );
	}

/*
	// ポケスロンショップ用
	if( wk->shop_type == SHOP_TYPE_POKETHLON || wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
		_pokethlon_flag_get( wk );
	}
*/

//	DummyShopDataSet( wk );

	// ショップアイテムリスト作成
	ShopItemSet( wk, item, 	SysFlag_MonsBallCheck( wk->evwk ), psitem );

	//FieldEvent_Set( repw, GMEVENT_Shop, wk );
	FieldEvent_Call( event, GMEVENT_Shop, wk );
}


//--------------------------------------------------------------------------------------------
/**
 * カメラ移動カウンタ取得
 *
 * @param	fsys	フィールドワーク
 *
 * @return	カウンタ
 *
 * @li	話しかけた向きによってカウンタ変化
 */
//--------------------------------------------------------------------------------------------
#ifndef NO_SHOP_SCROLL
static u8 CameraMoveCntGet( FIELDSYS_WORK * fsys )
{
	int	dir = Player_DirGet( fsys->player );

	if( dir == DIR_UP || dir == DIR_DOWN || dir == DIR_RIGHT ){
		return 10;
	}
	return 8;
}
#endif	// NO_SHOP_SCROLL


//--------------------------------------------------------------------------------------------
/**
 * @brief	フィールドイベント：メニュー制御
 * @param	event	フィールドイベント用パラメータ
 * @retval	TRUE	イベント終了
 * @retval	FALSE	イベント継続
 */
//--------------------------------------------------------------------------------------------
BOOL GMEVENT_Shop( GMEVENT_CONTROL * event )
{
	FIELDSYS_WORK * fsys;
	SHOP_WORK * wk;

	fsys = FieldEvent_GetFieldSysWork(event);
	wk   = FieldEvent_GetSpecialWork(event);

	switch( wk->seq ){
	case SHOP_SEQ_INIT:
#ifdef PM_DEBUG
		DEBUG_VIEW_HOOK(TRUE);		//デバッグ情報表示不許可
#endif
		ShopInitSeq( wk );
//		wk->seq = SHOP_SEQ_MENU;
		if( wk->mode == 0 ){
			wk->seq = SHOP_SEQ_BUY_INIT;	// 購入画面初期化
		}else{
			wk->seq = SHOP_SEQ_SALE_INIT;	// 「売る」初期化
		}
		break;

/*
	case SHOP_SEQ_MENU:
		wk->seq = ShopMenuSelect( wk );
		break;
*/

	case SHOP_SEQ_BUY_INIT:		// 購入画面初期化
		ShopBuyInitSeq( fsys, wk );
		// 下画面切り替え
		FieldSubLcdControler_ChangeApp( fsys, SUBLCD_MODE_SHOP_MENU, wk );
		wk->seq = SHOP_SEQ_BUY_SCROLL;
		break;

	case SHOP_SEQ_BUY_SCROLL:	// 購入位置へスクロール
		wk->seq = ShopBuyScrollSeq( fsys, wk );
		break;

	case SHOP_SEQ_BUY_SELECT:	// アイテム選択
		if(wk->touch_arret==SHOP_TOUCHCODE_NONE){
			wk->seq = ShopBuySelectSeq( wk );
		}else{
			wk->seq = ShopTouchSelect( wk, wk->touch_arret );
			wk->touch_arret = SHOP_TOUCHCODE_NONE;
		}
		break;

	case SHOP_SEQ_BUY_SELECT_RETURN:
		wk->seq = SHOP_SEQ_BUY_SELECT;
		break;
	case SHOP_CURSOR_ANIME_SELECT_WAIT:
		MORI_PRINT( "anm = %d, state = %d frame=%d, \n",CLACT_AnmGet(wk->cwp[SHOP_CLA_S_CURSOR]),
														CLACT_AnmActiveCheck( wk->cwp[SHOP_CLA_S_CURSOR]),
														CLACT_AnmFrameGet( wk->cwp[SHOP_CLA_S_CURSOR]) );
		if(CLACT_AnmActiveCheck( wk->cwp[SHOP_CLA_S_CURSOR])==FALSE){
			wk->seq = ShopDecideFunc( wk, wk->item[wk->cursor_pos+wk->scr] );

		}
		break;

/*
	case SHOP_CURSOR_ANIME_CANCEL_WAIT:
		if(CLACT_AnmActiveCheck( wk->cwp[SHOP_CLA_S_CURSOR])==FALSE){
			wk->seq = ShopCancelFunc( wk );
		}
		break;
*/

	case SHOP_SEQ_BUYSEL_WAIT:	// 「いくつ〜」表示ウェイト
		wk->seq = ShopBuySelWaitSeq( wk );
		break;

	case SHOP_SEQ_BUYNUM_SEL:	// 個数選択
		if(wk->touch_arret==SHOP_TOUCHCODE_NONE){
			wk->seq = ShopBuyNumSelSeq( wk );
		}else{
			wk->seq = ShopBuyNumTouchSelSeq( wk, wk->touch_arret );
			wk->touch_arret = SHOP_TOUCHCODE_NONE;
		}
		break;

	case SHOP_SEQ_BUYNUM_ENTER:	// 個数選択決定
		wk->seq = ShopBuyNumDecide( wk );
		break;

	case SHOP_SEQ_BUYNUM_CANCEL:
		wk->seq = ShopBuyNumCancel( wk );
		break;

	case SHOP_SEQ_BUYNUM_WAIT:	// 「合計〜なりますが」表示ウェイト
		wk->seq = ShopBuyNumWaitSeq( wk );
		break;

	case SHOP_SEQ_BUY_YESNO:	// はい・いいえ選択
		if(wk->touch_arret!=SHOP_TOUCHCODE_NONE){
			wk->seq = ShopBuyYesNoSeq( wk, wk->touch_arret );
			wk->touch_arret = SHOP_TOUCHCODE_NONE;
		}
		break;

	case SHOP_SEQ_BUY_CMP:		// 購入
		wk->seq = ShopBuyCmpSeq( wk );
		break;

	case SHOP_SEQ_BUYCMP_WAIT:	// アイテム選択へ
		wk->seq = ShopBuyCmpWaitSeq( wk );
		break;

	case SHOP_SEQ_CANT_BUY_WAIT:	// お金が足りなくて買えなかった
		wk->seq = ShopBuyCantWaitSeq( wk );
		break;

	case SHOP_SEQ_BUYOMAKE_WAIT:	// プレミアボール待ち
		wk->seq = ShopBuyOmakeWait( wk );
		break;

	case SHOP_SEQ_BUY_CANCEL:
		wk->seq = ShopCancelFunc( wk );
		break;

	case SHOP_SEQ_BUY_SUBLCD_END:	// 下画面復帰
		ShopBgPriorityReset( wk );
		ShopBuySublcdEnd(fsys,wk);
		wk->seq = SHOP_SEQ_BUY_END;
		break;
	case SHOP_SEQ_BUY_END:		// 購入画面終了
		wk->seq = ShopBuyEndSeq( fsys, wk );
		break;


	case SHOP_SEQ_BUY_PAGE_SUB:		// 前のページへ
		wk->seq = ShopBuyPageSub( wk );
		break;

	case SHOP_SEQ_BUY_PAGE_ADD:		// 次のページへ
		wk->seq = ShopBuyPageAdd( wk );
		break;

	case SHOP_SEQ_BUY_BUTTON_ANM:
		wk->seq = ButtonAnmMain( wk );
		break;

/*
	case SHOP_SEQ_MENU_RET:		// メニュー選択へ戻り待ち
		wk->seq = ShopBuyMenuRetSeq( wk );
		break;
*/

	case SHOP_SEQ_SALE_INIT:		// 「売る」初期化
		ShopSaleInitSeq( fsys, wk );
		break;

	case SHOP_SEQ_SALE_CALL:		// 「売る」呼び出し
		ShopSaleCallSeq( event );
		break;

	/* 常駐領域の処理に移動 ( fd_shop_sale.c ) */
	case SHOP_SEQ_SALE_WAIT:		// 「売る」終了待ち
	case SHOP_SEQ_SALE_RET:			// 「売る」終了 -> フェードイン
		break;

/*
	case SHOP_SEQ_SALE_WAIT:		// 「売る」終了待ち
		wk->seq = ShopSaleWaitSeq( fsys, wk );
		break;
	case SHOP_SEQ_SALE_RET:			// 「売る」終了 -> フェードイン
		wk->seq = ShopSaleRetSeq( fsys );
		break;
*/

	case SHOP_SEQ_SALE_MENU_RET:	// フェードイン -> メニューへ
		wk->seq = ShopSaleMenuRetSeq( fsys, wk );
		break;

/*
	case SHOP_SEQ_EXIT:
		ShopExitSeq( fsys, wk );
		wk->seq = SHOP_SEQ_END;
		break;
*/

	case SHOP_SEQ_END:
		return ShopEndSeq( fsys, wk );
	}

	// シーケンス限定でセルアクターを動作させる
//	if( wk->seq >= SHOP_SEQ_BUY_SELECT && wk->seq <= SHOP_SEQ_BUYOMAKE_WAIT ){

	{
		int	i;
		for( i=0; i<SHOP_CLA_MAX; i++ ){
			if( wk->cwp[i] != NULL ){
				CLACT_AnmFrameChg( wk->cwp[i], FX32_ONE );
			}
		}
	}
/*
		if( wk->cwp[0] != NULL ){
			CLACT_AnmFrameChg( wk->cwp[0], FX32_ONE );
		}
		if( wk->cwp[1] != NULL ){
			CLACT_AnmFrameChg( wk->cwp[1], FX32_ONE );
		}
*/
		if( wk->fcat.cas != NULL ){
			CLACT_Draw( wk->fcat.cas );
		}
//	}


	return FALSE;
}


//--------------------------------------------------------------------------------------------
/**
 * 初期化
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopInitSeq( SHOP_WORK * wk )
{
	ShopMsgCreate( wk );
//	ShopMenuSet( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージ関連作成
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopMsgCreate( SHOP_WORK * wk )
{
	wk->mman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_shop_dat, HEAPID_WORLD );
	wk->wset = WORDSET_Create( HEAPID_WORLD );
}

//--------------------------------------------------------------------------------------------
/**
 * ショップメニュー作成
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
/*
static void ShopMenuSet( SHOP_WORK * wk )
{
	BMPMENU_HEADER	hed;
	u8	max;

	// ショップがどうぐを売っている
	if( wk->shop_type == SHOP_TYPE_ITEM ){
		max = 3;
		wk->md = BMP_MENULIST_Create( max, HEAPID_WORLD );
		BMP_MENULIST_AddArchiveString( wk->md, wk->mman, mes_shop_04_01, SHOP_SEQ_BUY_INIT );
		BMP_MENULIST_AddArchiveString( wk->md, wk->mman, mes_shop_04_02, SHOP_SEQ_SALE_INIT );
		BMP_MENULIST_AddArchiveString( wk->md, wk->mman, mes_shop_04_03, BMPMENU_CANCEL );

		GF_BGL_BmpWinAdd(
			wk->bgl, &wk->win[WIN_IDX_NENU], FLD_MBGFRM_FONT,
			WIN_SHOP_MENU_PX, WIN_SHOP_MENU_PY, WIN_SHOP_MENU_SX,
			WIN_SHOP_MENU_SY, WIN_SHOP_MENU_PAL, WIN_SHOP_MENU_CGX );

	// ショップが秘密基地グッズかシールを売っている
	}else{
		max = 2;
		wk->md = BMP_MENULIST_Create( max, HEAPID_WORLD );
		BMP_MENULIST_AddArchiveString( wk->md, wk->mman, mes_shop_04_01, SHOP_SEQ_BUY_INIT );
		BMP_MENULIST_AddArchiveString( wk->md, wk->mman, mes_shop_04_03, BMPMENU_CANCEL );

		GF_BGL_BmpWinAdd(
			wk->bgl, &wk->win[WIN_IDX_NENU], FLD_MBGFRM_FONT,
			WIN_SHOP_MENU_PX, WIN_SHOP_MENU_PY, WIN_SHOP_MENU_SX,
			WIN_SHOP_MENU_SY_GS, WIN_SHOP_MENU_PAL, WIN_SHOP_MENU_CGX );
	}

	hed.menu     = wk->md;
	hed.win      = &wk->win[WIN_IDX_NENU];
	hed.font     = FONT_SYSTEM;
	hed.x_max    = 1;
	hed.y_max    = max;
	hed.line_spc = 0;
	hed.c_disp_f = 0;
	hed.loop_f   = 0;

	MenuWinGraphicSet(
		wk->bgl, FLD_MBGFRM_FONT, MENU_WIN_CGX_NUM, MENU_WIN_PAL, 0, HEAPID_WORLD );
	BmpMenuWinWrite( &wk->win[WIN_IDX_NENU], WINDOW_TRANS_OFF, MENU_WIN_CGX_NUM, MENU_WIN_PAL );
	wk->mw = BmpMenuAddEx( &hed, 8, 0, 0, HEAPID_WORLD, PAD_BUTTON_CANCEL );
}
*/

//--------------------------------------------------------------------------------------------
/**
 * メニュー選択
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
/*
static u8 ShopMenuSelect( SHOP_WORK * wk )
{
	u32	ret = BmpMenuMain( wk->mw );

	switch( ret ){
	case BMPMENU_NULL:
		break;
	case BMPMENU_CANCEL:
		ShopMenuExit( wk );
		return SHOP_SEQ_EXIT;
	default:
		return (u8)ret;
	}
	return SHOP_SEQ_MENU;
}
*/

//--------------------------------------------------------------------------------------------
/**
 * メニュー削除
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
/*
static void ShopMenuExit( SHOP_WORK * wk )
{
	BmpMenuWinClear( &wk->win[WIN_IDX_NENU], WINDOW_TRANS_OFF );
	GF_BGL_BmpWinOff( &wk->win[WIN_IDX_NENU] );

	BmpMenuExit( wk->mw, NULL );
	BMP_MENULIST_Delete( wk->md );

	GF_BGL_BmpWinDel( &wk->win[WIN_IDX_NENU] );
}
*/

//--------------------------------------------------------------------------------------------
/**
 * ショップ処理終了
 *
 * @param	fsys	フィールドワーク
 * @param	wk		ショップワーク
 *
 * @retval	"TRUE = 終了"
 * @retval	"FALSE = 処理中"
 */
//--------------------------------------------------------------------------------------------
static u8 ShopEndSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
	MSGMAN_Delete( wk->mman );
	WORDSET_Delete( wk->wset );

	STRBUF_Delete( wk->msgb );

	sys_FreeMemoryEz( wk->item );
	sys_FreeMemoryEz( wk );

#ifdef PM_DEBUG
	DEBUG_VIEW_HOOK(FALSE);			//デバッグ情報表示許可
#endif
	return TRUE;
}



//=============================================================================================
//	買う
//=============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * 購入処理初期化
 *
 * @param	fsys	フィールドワーク
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyInitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
//	BmpTalkWinClear( &wk->win[WIN_IDX_FLDTALK], WINDOW_TRANS_ON );
	GF_BGL_ScrFill(
		wk->bgl, FLD_MBGFRM_FONT, 0,
		FLD_MSG_WIN_PX-2,FLD_MSG_WIN_PY-1,FLD_MSG_WIN_SX+5,FLD_MSG_WIN_SY+2, 0 );
	GF_BGL_LoadScreenV_Req( wk->bgl, FLD_MBGFRM_FONT );

//	ShopMenuExit( wk );
	ShopBuyWinAdd( wk );
//	ShopBuyGraphicSet( wk );

	wk->camera = GFC_AllocCamera( HEAPID_WORLD );
	GFC_CopyCamera( fsys->camera_ptr, wk->camera );
	GFC_AttachCamera( wk->camera );
	wk->cm_cnt = 0;
}

//--------------------------------------------------------------------------------------------
/**
 * 購入処理のBMP作成
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyWinAdd( SHOP_WORK * wk )
{
	u32	i;

	for( i=0; i<WIN_IDX_MAX; i++ ){
		if( wk->shop_type != SHOP_TYPE_ITEM &&
			wk->shop_type != SHOP_TYPE_POKETHLON &&
			wk->shop_type != SHOP_TYPE_POKETHLON_CARD &&
			i == WIN_IDX_INFO ){
			GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &ShopBuyGoodsInfoWin );
		}else{
			GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &ShopBuyBmpWin[i] );
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 購入処理のBMP削除
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyWinDel( SHOP_WORK * wk )
{
	u32	i;

	BmpMenuWinClear( &wk->win[WIN_IDX_GOLD], WINDOW_TRANS_OFF );

	for( i=0; i<WIN_IDX_MAX; i++ ){
		GF_BGL_BmpWinOffVReq( &wk->win[i] );
		GF_BGL_BmpWinDel( &wk->win[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 購入処理のグラフィックセット
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyGraphicSet( SHOP_WORK * wk )
{
	ArcUtil_BgCharSet(
		ARC_SHOP_GRA, NARC_shop_gra_shop_bg_NCGR,
		wk->bgl, SHOP_FRM_BG, 0, 0, 0, HEAPID_WORLD );
	if( wk->shop_type == SHOP_TYPE_ITEM ||
		wk->shop_type == SHOP_TYPE_POKETHLON ||
		wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
		ArcUtil_ScrnSet(
			ARC_SHOP_GRA, NARC_shop_gra_shop_bg1_NSCR,
			wk->bgl, SHOP_FRM_BG, 0, 0, 0, HEAPID_WORLD );
	}else{
		ArcUtil_ScrnSet(
			ARC_SHOP_GRA, NARC_shop_gra_shop_bg2_NSCR,
			wk->bgl, SHOP_FRM_BG, 0, 0, 0, HEAPID_WORLD );
	}
	ArcUtil_PalSet(
		ARC_SHOP_GRA, NARC_shop_gra_shop_bg_NCLR, PALTYPE_MAIN_BG, 0, 32, HEAPID_WORLD );

	// メニューウィンドウセット
	MenuWinGraphicSet(
		wk->bgl, SHOP_FRM_WINDOW, SHOP_MENU_WIN_CGX, MENU_WIN_PAL, 0, HEAPID_WORLD );
	// 会話ウィンドウセット
	TalkWinGraphicSet(
		wk->bgl, SHOP_FRM_WINDOW, SHOP_TALK_WIN_CGX,
		TALK_WIN_PAL, CONFIG_GetWindowType(wk->cfg), HEAPID_WORLD );
}

//--------------------------------------------------------------------------------------------
/**
 * 購入処理のBGプライオリティ設定
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBgPriorityChg( SHOP_WORK * wk )
{
	wk->disp = GF_Disp_MainVisibleGet();

	wk->pri[0] = GF_BGL_PriorityGet( wk->bgl, SHOP_FRM_3D );
	wk->pri[1] = GF_BGL_PriorityGet( wk->bgl, SHOP_FRM_BG );
	wk->pri[2] = GF_BGL_PriorityGet( wk->bgl, SHOP_FRM_LIST );
	wk->pri[3] = GF_BGL_PriorityGet( wk->bgl, SHOP_FRM_WINDOW );

	GF_BGL_PrioritySet( SHOP_FRM_3D, 3 );
	GF_BGL_PrioritySet( SHOP_FRM_BG, 2 );
	GF_BGL_PrioritySet( SHOP_FRM_LIST, 1 );
	GF_BGL_PrioritySet( SHOP_FRM_WINDOW, 0 );

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG0, VISIBLE_ON );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG1, VISIBLE_ON );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2, VISIBLE_ON );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG3, VISIBLE_ON );
}

//--------------------------------------------------------------------------------------------
/**
 * フィールドのBGプライオリティに復帰
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBgPriorityReset( SHOP_WORK * wk )
{
	GF_BGL_PrioritySet( SHOP_FRM_3D, wk->pri[0] );
	GF_BGL_PrioritySet( SHOP_FRM_BG, wk->pri[1] );
	GF_BGL_PrioritySet( SHOP_FRM_LIST, wk->pri[2] );
	GF_BGL_PrioritySet( SHOP_FRM_WINDOW, wk->pri[3] );

	GF_Disp_GX_VisibleControlDirect( wk->disp );
}

//--------------------------------------------------------------------------------------------
/**
 * 購入処理開始カメラスクロール（上画面）
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyScrollSeq( FIELDSYS_WORK *fsys, SHOP_WORK * wk )
{
#ifndef NO_SHOP_SCROLL
	// スクロール無し
	if( wk->cm_cnt != wk->cm_max ){
		VecFx32 move = {8*FX32_ONE,0,0};
		GFC_ShiftCamera( &move, wk->camera );
		wk->cm_cnt++;
		return SHOP_SEQ_BUY_SCROLL;
	}
#endif
/*
		if( sys.trg & PAD_KEY_UP ){
			move.z = FX32_ONE;
			GFC_ShiftCamera( &move, wk->camera );
		}else if( sys.trg & PAD_KEY_DOWN ){
			move.z = FX32_ONE;
			GFC_ShiftCamera( &move, wk->camera );
		}else if( sys.trg & PAD_KEY_LEFT ){
			move.x = FX32_ONE;
			GFC_ShiftCamera( &move, wk->camera );
		}else if( sys.trg & PAD_KEY_RIGHT ){
			move.x = FX32_ONE;
			GFC_ShiftCamera( &move, wk->camera );
		}
*/
	// 下画面が切り替わるのを待つ
	if( FieldSubLcdControler_GetSequence( fsys ) != SUBLCD_SEQ_MAIN ){
		return SHOP_SEQ_BUY_SCROLL;
	}

	wk->cm_cnt = 0;
	ShopBuyGraphicSet( wk );
	ShopBgPriorityChg( wk );
//	ShopBuyItemListMake( wk );
//	ShopBuyGoldWinPut( wk, 0 );
//	ShopItemIconPageChange( wk, wk->scr, wk->max );
	// どうぐ情報更新
	ShopBuyItemInfoChange( wk, wk->cursor_pos );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ITEMICON], 1 );

	return SHOP_SEQ_BUY_SELECT;
}

/*
// アイテムリストデータ（BMPリスト）
static const BMPLIST_HEADER ShopItemList = {
	NULL, CB_ItemListMove, CB_ItemListWrite, NULL,
	0, 7, 0,
	0, 0,			// 項目X, カーソルX
	0,				// 表示Y
	FBMP_COL_BLACK, FBMP_COL_NULL, FBMP_COL_BLK_SDW,
	0, 16,						// 文字間隔Ｙ
	BMPLIST_NO_SKIP, FONT_SYSTEM, 1,
	NULL,
};
*/

//--------------------------------------------------------------------------------------------
/**
 * 商品のID取得
 *
 * @param	wk		ショップワーク
 * @param	item	アイテムID
 *
 * @return	商品のID
 *
 * @li	道具、グッズ、シール
 */
//--------------------------------------------------------------------------------------------
/*
static u32 ShopByeGetItemNameID( SHOP_WORK * wk, u16 item )
{
	if( wk->shop_type == SHOP_TYPE_GOODS ){
		return (UGGoods001+item-1);
	}else if( wk->shop_type == SHOP_TYPE_SEAL ){
		return (u32)Seal_NameGet( (u8)item );
	}
	return (u32)item;
}
*/

//--------------------------------------------------------------------------------------------
/**
 * 商品のBMPリスト作成
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
/*
static void ShopBuyItemListMake( SHOP_WORK * wk )
{
	MSGDATA_MANAGER * man;
	STRBUF * buf;
	BMPLIST_HEADER	lh;
	u32	i;

	if( wk->shop_type == SHOP_TYPE_ITEM ){
		man = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_itemname_dat, HEAPID_WORLD );
	}else if( wk->shop_type == SHOP_TYPE_GOODS ){
		man = MSGMAN_Create(MSGMAN_TYPE_NORMAL,ARC_MSG,NARC_msg_undergroundgoods_dat,HEAPID_WORLD);
	}else{
		man = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, CB_SEAL_MSG_ARC, HEAPID_WORLD );
	}

	wk->ld = BMP_MENULIST_Create( wk->max+1, HEAPID_WORLD );
	for( i=0; i<wk->max; i++ ){
		buf = MSGMAN_AllocString( man, ShopByeGetItemNameID( wk, wk->item[i] ) );
		BMP_MENULIST_AddString( wk->ld, buf, wk->item[i] );
		STRBUF_Delete( buf );
	}
	BMP_MENULIST_AddArchiveString( wk->ld, wk->mman, mes_shop_02_06, BMPLIST_CANCEL );

	MSGMAN_Delete( man );

	lh = ShopItemList;
	lh.list  = wk->ld;
	lh.win   = &wk->win[WIN_IDX_LIST];
	lh.count = wk->max+1;
	lh.work  = (void *)wk;
	wk->lw = BmpListSet( &lh, 0, 0, HEAPID_WORLD );
}
*/

//--------------------------------------------------------------------------------------------
/**
 * アイテムリストコールバック関数（カーソル移動ごと）
 *
 * @param	work	BMPリストで設定したワーク
 * @param	param	BMPリストのパラメータ
 * @param	mode	初期化時 = 1
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
/*
static void CB_ItemListMove( BMPLIST_WORK * work, u32 param, u8 mode )
{
	SHOP_WORK * wk = (SHOP_WORK *)BmpListParamGet( work, BMPLIST_ID_WORK );

	if( mode != 1 ){
		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
	}

#if 0
	GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_INFO], 0 );

	if( param != BMPLIST_CANCEL ){
		STRBUF * buf;

		if( wk->shop_type == SHOP_TYPE_ITEM ){
			buf = STRBUF_Create( BUFLEN_ITEM_INFO, HEAPID_WORLD );
			ItemInfoGet( buf, (u16)param, HEAPID_WORLD );
		}else if( wk->shop_type == SHOP_TYPE_GOODS ){
			MSGDATA_MANAGER * man;
			man = MSGMAN_Create(
					MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_undergroundgoods_dat, HEAPID_WORLD );
			buf = MSGMAN_AllocString( man, UGGoods_e001+param-1 );
			MSGMAN_Delete( man );
		}else{
			MSGDATA_MANAGER * man;
			man = MSGMAN_Create(
					MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_seal_comment_dat, HEAPID_WORLD );
			buf = MSGMAN_AllocString( man, Seal_CommentGet((u8)param) );
			MSGMAN_Delete( man );
		}
		GF_STR_PrintColor(
			&wk->win[WIN_IDX_INFO], FONT_SYSTEM, buf, 0, 0, MSG_NO_PUT, SHOPCOL_N_WHITE, NULL );
		STRBUF_Delete( buf );

		ShopBuyItemIconChg( wk,  (u16)param );
	}else{
		ShopBuyItemIconChg( wk,  ITEM_RETURN_ID );
	}
	GF_BGL_BmpWinOnVReq( &wk->win[WIN_IDX_INFO] );
#endif

	{
		u32	max;
		u16	scr, cur;

		BmpListPosGet( work, &scr, &cur );
		if( scr == 0 ){
			CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], 0 );
		}else{
			CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], 0 );
		}

		max = BmpListParamGet( work, BMPLIST_ID_COUNT );
		if( max > 7 && max > scr + 7 ){
			CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], 0 );
		}else{
			CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], 0 );
		}
	}
}
*/

//#define	LIST_PRICE_BUFLEN	( 12 )
//#define	LIST_PRICE_EX		( WIN_SHOP_LIST_SX * 8 )

//--------------------------------------------------------------------------------------------
/**
 * アイテムリストコールバック関数（一列表示ごと）
 *
 * @param	work	BMPリストで設定したワーク
 * @param	index	BMPリストが使用しているウィンドウインデックス
 * @param	param	BMPリストのパラメータ
 * @param	y		Y座標
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
/*
static void CB_ItemListWrite( BMPLIST_WORK * work, u32 param, u8 y )
{
	SHOP_WORK * wk = (SHOP_WORK *)BmpListParamGet( work, BMPLIST_ID_WORK );

	if( param != BMPLIST_CANCEL ){
		STRBUF * expb;
		STRBUF * strb;
		u32	price;
		u32	siz;

		price = ShopBuyItemPriceGet( wk, (u16)param );
		expb  = STRBUF_Create( LIST_PRICE_BUFLEN, HEAPID_WORLD );
		strb  = MSGMAN_AllocString( wk->mman, mes_shop_02_07 );
		WORDSET_RegisterNumber(
			wk->wset, 0, price, 4, NUMBER_DISPTYPE_SPACE, NUMBER_CODETYPE_DEFAULT );
		WORDSET_ExpandStr( wk->wset, expb, strb );
		siz = FontProc_GetPrintStrWidth( FONT_SYSTEM, expb, 0 );
		GF_STR_PrintColor(
			&wk->win[WIN_IDX_LIST], FONT_SYSTEM, expb,
			LIST_PRICE_EX-siz, y, MSG_NO_PUT, SHOPCOL_N_BLACK, NULL );
		STRBUF_Delete( strb );
		STRBUF_Delete( expb );
	}
}
*/


#if 0
#define	GOLD_BUFLEN		( 16 )
#define	GOLD_EX			( WIN_SHOP_GOLD_SX * 8 )
//--------------------------------------------------------------------------------------------
/**
 * 所持金表示
 *
 * @param	wk		ショップワーク
 * @param	flg		ウィンドウ枠描画フラグ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyGoldWinPut( SHOP_WORK * wk, u8 flg )
{
	STRBUF * expb;
	STRBUF * strb;
	u32	gold;
	u32	siz;

	if( flg == 0 ){
		GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_GOLD], 15 );
		BmpMenuWinWrite(
			&wk->win[WIN_IDX_GOLD], WINDOW_TRANS_OFF, SHOP_MENU_WIN_CGX, MENU_WIN_PAL );
		strb = MSGMAN_AllocString( wk->mman, mes_shop_05_01 );
		GF_STR_PrintSimple( &wk->win[WIN_IDX_GOLD], FONT_SYSTEM, strb, 0, 0, MSG_NO_PUT, NULL );
		STRBUF_Delete( strb );
	}else{
		GF_BGL_BmpWinFill( &wk->win[WIN_IDX_GOLD], 15, 0, 16, GOLD_EX, 16 );
	}

	expb = STRBUF_Create( GOLD_BUFLEN, HEAPID_WORLD );
	strb = MSGMAN_AllocString( wk->mman, mes_shop_05_02 );
	gold = MyStatus_GetGold( wk->my );
	WORDSET_RegisterNumber(
		wk->wset, 0, gold, 6, NUMBER_DISPTYPE_SPACE, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, expb, strb );
	siz = FontProc_GetPrintStrWidth( FONT_SYSTEM, expb, 0 );
	GF_STR_PrintSimple(
		&wk->win[WIN_IDX_GOLD], FONT_SYSTEM, expb, GOLD_EX-siz, 16, MSG_NO_PUT, NULL );
	STRBUF_Delete( strb );
	STRBUF_Delete( expb );
	GF_BGL_BmpWinOnVReq( &wk->win[WIN_IDX_GOLD] );
}

#endif

typedef struct{
	u8 up,down,left,right;
}ARROW4_TBL;

// 上下左右の順
// ショップのカーソルの移動
static const ARROW4_TBL _key_table[]={

	{ CURSORPOS_ITEM4, 		CURSORPOS_ITEM2, 	CURSORPOS_SUBPAGE, 	CURSORPOS_ITEM1, 	},		// 真ん中の６個
	{ CURSORPOS_END, 		CURSORPOS_ITEM3, 	CURSORPOS_ITEM0, 	CURSORPOS_ADDPAGE, 	},
	{ CURSORPOS_ITEM0, 		CURSORPOS_ITEM4,	CURSORPOS_SUBPAGE, 	CURSORPOS_ITEM3, 	},
	{ CURSORPOS_ITEM1, 		CURSORPOS_ITEM5,	CURSORPOS_ITEM2, 	CURSORPOS_ADDPAGE, 	},
	{ CURSORPOS_ITEM2, 		CURSORPOS_ITEM0,	CURSORPOS_SUBPAGE, 	CURSORPOS_ITEM5, 	},
	{ CURSORPOS_ITEM3, 		CURSORPOS_END,		CURSORPOS_ITEM4, 	CURSORPOS_ADDPAGE, 	},

	{ CURSORPOS_ITEM4,  	CURSORPOS_ITEM0,	CURSORPOS_END, 	CURSORPOS_END,		},		// 下の３個
	{ CURSORPOS_ITEM4,  	CURSORPOS_ITEM0,	CURSORPOS_END, 	CURSORPOS_END,		},
	{ CURSORPOS_ITEM5,  	CURSORPOS_ITEM1,	CURSORPOS_END, 	CURSORPOS_END,		},
};

//------------------------------------------------------------------
/**
 * @brief   カーソルアクターセット
 *
 * @param   wk
 * @param   pos		カーソル位置
 * @param   mode	SHOP_MODE_LIST or SHOP_MODE_SELECT
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void ShopCursorActPosSet( SHOP_WORK *wk, int pos, int mode )
{
	switch(mode){
	case SHOP_MODE_LIST:
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_CURSOR], shop_cursor_pos[wk->cursor_pos].anim );
		CATS_ObjectPaletteSet( wk->cwp[SHOP_CLA_S_CURSOR], shop_cursor_pos[pos].pal );
		CATS_ObjectPosSet( wk->cwp[SHOP_CLA_S_CURSOR],
							shop_cursor_pos[pos].x,
							shop_cursor_pos[pos].y  );
		break;
	case SHOP_MODE_SELECT:
	case SHOP_MODE_SELECT_EX:
		break;
	}
}

//------------------------------------------------------------------
/**
 * @brief   どうぐ説明の更新処理
 *
 * @param   wk
 * @param   pos		カーソル位置
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void ShopBuyItemInfoChange( SHOP_WORK *wk, int pos )
{
	u16 param = wk->item[wk->cursor_pos+wk->scr];

	switch(pos){
	case CURSORPOS_ITEM0: case CURSORPOS_ITEM1:	case CURSORPOS_ITEM2:
	case CURSORPOS_ITEM3: case CURSORPOS_ITEM4:	case CURSORPOS_ITEM5:
		GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_INFO], 0 );
		if( wk->cursor_pos+wk->scr<wk->max ){
			STRBUF * buf;

			if( wk->shop_type == SHOP_TYPE_ITEM || wk->shop_type == SHOP_TYPE_POKETHLON || wk->shop_type == SHOP_TYPE_POKETHLON_CARD){
				buf = STRBUF_Create( BUFLEN_ITEM_INFO, HEAPID_WORLD );
				ItemInfoGet( buf, param, HEAPID_WORLD );
			}else if( wk->shop_type == SHOP_TYPE_GOODS ){
				MSGDATA_MANAGER * man;
				man = MSGMAN_Create(
						MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_undergroundgoods_dat, HEAPID_WORLD );
				buf = MSGMAN_AllocString( man, UGGoods_e001+param-1 );
				MSGMAN_Delete( man );
			}else{
				MSGDATA_MANAGER * man;
				man = MSGMAN_Create(
						MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_seal_comment_dat, HEAPID_WORLD );
				buf = MSGMAN_AllocString( man, Seal_CommentGet(param) );
				MSGMAN_Delete( man );
			}
			GF_STR_PrintColor(
				&wk->win[WIN_IDX_INFO], FONT_SYSTEM, buf, 0, 0, MSG_NO_PUT, SHOPCOL_N_WHITE, NULL );
			STRBUF_Delete( buf );

			ShopBuyItemIconChg( wk, param );
		}else{
			CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ITEMICON], 0 );
		}
		GF_BGL_BmpWinOnVReq( &wk->win[WIN_IDX_INFO] );
		break;
	case CURSORPOS_SUBPAGE:	case CURSORPOS_ADDPAGE:
		break;
	case CURSORPOS_END:
		GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_INFO], 0 );
		ShopBuyItemIconChg( wk,  ITEM_RETURN_ID );
		GF_BGL_BmpWinOnVReq( &wk->win[WIN_IDX_INFO] );
		break;
	}

}


//--------------------------------------------------------------------------------------------
/**
 * 購入アイテム選択
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuySelectSeq( SHOP_WORK * wk )
{
	u32	ret;
	u16	cur1, cur2;
	int refresh = 0;

//	BmpListPosGet( wk->lw, NULL, &cur1 );
//	ret = BmpListMain( wk->lw );
//	BmpListPosGet( wk->lw, NULL, &cur2 );

//	if( cur1 != cur2 ){
//		CATS_ObjectPosSet( wk->cwp[2], CURSOR_ACT_PX, CURSOR_ACT_PY + cur2 * 16 );
//	}

	if(sys.trg&PAD_KEY_UP){
		wk->cursor_pos = _key_table[wk->cursor_pos].up;
		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
		refresh++;
	}else if(sys.trg&PAD_KEY_DOWN){
		wk->cursor_pos = _key_table[wk->cursor_pos].down;
		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
		refresh++;
	}else if(sys.trg&PAD_KEY_LEFT){
		if(_key_table[wk->cursor_pos].left==CURSORPOS_SUBPAGE){
			return ShopTouchSelect( wk, CURSORPOS_SUBPAGE );
		}else if( wk->cursor_pos != CURSORPOS_END ){
			wk->cursor_pos = _key_table[wk->cursor_pos].left;
			Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
			refresh++;
		}
	}else if(sys.trg&PAD_KEY_RIGHT){
		if(_key_table[wk->cursor_pos].right==CURSORPOS_ADDPAGE){
			return ShopTouchSelect( wk, CURSORPOS_ADDPAGE );
		}else if( wk->cursor_pos != CURSORPOS_END ){
			wk->cursor_pos = _key_table[wk->cursor_pos].right;
			Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
			refresh++;
		}
	}

	if(refresh){
//		CATS_ObjectAnimeSeqSetCap( wk->cwp[SHOP_CLA_S_CURSOR], shop_cursor_pos[wk->cursor_pos].anim );
//		CATS_ObjectPaletteSetCap( wk->cwp[SHOP_CLA_S_CURSOR], shop_cursor_pos[wk->cursor_pos].pal );

		// カーソル形状・位置セット
		ShopCursorActPosSet( wk, wk->cursor_pos, SHOP_MODE_LIST );

		// どうぐ情報更新
		ShopBuyItemInfoChange( wk, wk->cursor_pos );

	}

	if( sys.trg & PAD_BUTTON_CANCEL ){
		Snd_SePlay( FD_SHOP_SE_CLOSE );
//		return ShopCancelFunc( wk );
		return ButtonAnmSet( wk, SHOP_CLA_S_CANCEL, SHOP_SEQ_BUY_CANCEL );

	}else if( sys.trg & PAD_BUTTON_DECIDE ){
		return ShopTouchSelect( wk, wk->cursor_pos );
//		return ShopDecideFunc( wk, ret );
	}
#if 0
	switch( ret ){
	case BMPLIST_NULL:
		break;
	case BMPLIST_CANCEL:
		// キャンセル処理
		Snd_SePlay( FD_SHOP_SE_CANCEL );
		return ShopCancelFunc( wk );

	default:

		// 決定処理
		return ShopDecideFunc( wk, ret );
	}
#endif
	return SHOP_SEQ_BUY_SELECT;
}



//------------------------------------------------------------------
/**
 * @brief   タッチ入力があったときの挙動
 *
 * @param   wk
 * @param   arret	タッチで行われた決定
 *
 * @retval  u8		次のシーケンス
 */
//------------------------------------------------------------------
static u8 ShopTouchSelect( SHOP_WORK *wk, u32 arret )
{
	switch(arret){
	case CURSORPOS_ITEM0:	case CURSORPOS_ITEM1: case CURSORPOS_ITEM2:
	case CURSORPOS_ITEM3:	case CURSORPOS_ITEM4: case CURSORPOS_ITEM5:
		if( arret+wk->scr < wk->max  ){
			wk->cursor_pos = arret;
			ShopCursorActPosSet( wk, wk->cursor_pos, SHOP_MODE_LIST );
			CLACT_AnmChg( wk->cwp[SHOP_CLA_S_CURSOR], 19 );
			Snd_SePlay( FD_SHOP_SE_DECIDE );
			ShopBuyItemInfoChange( wk, wk->cursor_pos );
			return SHOP_CURSOR_ANIME_SELECT_WAIT;
		}
		break;

	case CURSORPOS_SUBPAGE:
		if(wk->scr != 0){
			Snd_SePlay( FD_SHOP_SE_DECIDE );
			return ButtonAnmSet( wk, SHOP_CLA_S_PAGEDOWN, SHOP_SEQ_BUY_PAGE_SUB );
		}
		break;

	case CURSORPOS_ADDPAGE:
		if(wk->scr+6 < wk->max){
			Snd_SePlay( FD_SHOP_SE_DECIDE );
			return ButtonAnmSet( wk, SHOP_CLA_S_PAGEUP, SHOP_SEQ_BUY_PAGE_ADD );
		}
		break;

	case CURSORPOS_END:
		ShopCursorActPosSet( wk, arret, SHOP_MODE_LIST );
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_CURSOR], 7 );
		Snd_SePlay( FD_SHOP_SE_CLOSE );
		ShopBuyItemInfoChange( wk, CURSORPOS_END );
//		return SHOP_CURSOR_ANIME_CANCEL_WAIT;
		return ButtonAnmSet( wk, SHOP_CLA_S_CANCEL, SHOP_SEQ_BUY_CANCEL );

	default:
		break;
	}

	return SHOP_SEQ_BUY_SELECT;
}

static u8 ShopBuyPageSub( SHOP_WORK * wk )
{
	wk->scr -= 6;
	ShopItemIconPageChange( wk, wk->scr, wk->max );
	wk->sublcd_refresh = SUBLCD_REFRESH_LIST;
	ShopBuyItemInfoChange( wk, wk->cursor_pos );

	return SHOP_SEQ_BUY_SELECT;
}

static u8 ShopBuyPageAdd( SHOP_WORK * wk )
{
	wk->scr += 6;
	ShopItemIconPageChange( wk, wk->scr, wk->max );
	wk->sublcd_refresh = SUBLCD_REFRESH_LIST;
	ShopBuyItemInfoChange( wk, wk->cursor_pos );

	return SHOP_SEQ_BUY_SELECT;
}


//------------------------------------------------------------------
/**
 * @brief   ページ再描画時にどうぐアイコンと表示・非表示を設定する
 *
 * @param   wk
 * @param   scr
 * @param   max
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void ShopItemIconPageChange( SHOP_WORK * wk, int scr, int max )
{
	int i;

	for(i=0;i<SHOP_PAGE_ITEM_NUM;i++){
		if(i<MATH_CLAMP(max-scr, 0, SHOP_PAGE_ITEM_NUM)){
			ShopBuySubLCDItemIconChg( wk, CLA_ID_S_ITEMICON0+i, 2+i,  wk->item[i+scr] );

//			ItemIconChange(wk, i, wk->item[i] );
			CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_ITEMICON0+i], 1 );
		}else{
			CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_ITEMICON0+i], 0 );

		}
	}
	ShopSubActVisible( wk, SHOP_MODE_LIST );

}





//------------------------------------------------------------------
/**
 * @brief   キャンセル処理
 *
 * @param   wk
 *
 * @retval  u8
 */
//------------------------------------------------------------------
static u8 ShopCancelFunc( SHOP_WORK *wk )
{
//	BmpListExit( wk->lw, NULL, NULL );
//	BMP_MENULIST_Delete( wk->ld );
	ShopBuyWinDel( wk );
//	ShopBgPriorityReset( wk );
//	GF_BGL_ScrClear( wk->bgl, SHOP_FRM_BG );
	GF_BGL_ScrClearCodeVReq( wk->bgl, SHOP_FRM_BG, 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ITEMICON], 0 );
//	Snd_SePlay( FD_SHOP_SE_CANCEL );

	return SHOP_SEQ_BUY_SUBLCD_END;
}


//------------------------------------------------------------------
/**
 * @brief   ショップのタイプによってお金かポケスロンポイントを取得
 *
 * @param   wk
 * @param   type
 *
 * @retval  u32
 */
//------------------------------------------------------------------
static u32 _get_gold_point( SHOP_WORK *wk, int type )
{
	if(type==SHOP_TYPE_POKETHLON || type==SHOP_TYPE_POKETHLON_CARD){
		return PkthlnSv_GetThlnPoint ( wk->pokethlon_save );
	}
	return MyStatus_GetGold( wk->my );
}


//==============================================================================
/**
 * @brief   購入できるかチェック（ノーマル・ポケスロン対応版）
 *
 * @param   wk
 * @param   gold	所持金か所持ポイントか
 *
 * @retval  int
 */
//==============================================================================
int ShopCheckBuyItem( SHOP_WORK *wk, int gold )
{
	if(wk->shop_type==SHOP_TYPE_POKETHLON ){
		// ポケスロンショップですでに買っている
		if( PkthlnSv_GetShopFlag( wk->pokethlon_save, wk->cursor_pos+wk->scr ) ){
			return 2;
		}
	}else if(wk->shop_type==SHOP_TYPE_POKETHLON_CARD ){
		// ポケスロンカードショップですでに買っている
		if( PkthlnSv_GetRankingAppear( wk->pokethlon_save, wk->sel_item-ITEM_DEETAKAADO01 ) ){
			return 3;
		}
	}

	if(gold < wk->sel_price){
		return 1;
	}

	return 0;
}

//------------------------------------------------------------------
/**
 * @brief   選択しているどうぐを決定
 *
 * @param   wk
 * @param   decide	BMPLISTの返り値かタッチの結果
 *
 * @retval  int		次のシーケンス
 */
//------------------------------------------------------------------
static int ShopDecideFunc( SHOP_WORK *wk, int decide )
{
	STRBUF * str;
	u32	gold;

	wk->scr_draw[0] = (u16)CLACT_GetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U] );
	wk->scr_draw[1] = (u16)CLACT_GetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D] );

	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], 0 );

	ShopBuyCursorPalChg( wk, 1 );

	wk->sel_item  = (u16)decide;
	wk->sel_num   = 1;
	wk->sel_price = ShopBuyItemPriceGet( wk, wk->sel_item );


	// 所持金・所持ポイントを取得
	gold = _get_gold_point( wk, wk->shop_type );

	// 購入できるか比較
	if( ShopCheckBuyItem( wk, gold ) ){
		wk->sublcd_refresh = SUBLCD_REFRESH_CANT_BUY;
		return SHOP_SEQ_CANT_BUY_WAIT;
	}

/*
	if( wk->shop_type == SHOP_TYPE_GOODS ){
#if AFTERMASTER_070122_GOODSSHOP_SE
//		Snd_SePlay( FD_SHOP_SE_DECIDE );
#endif
		return ShopBuyCmpCheck( wk );
	}
*/

	wk->sel_max = gold / wk->sel_price;
	if( wk->sel_max > 99 ){ wk->sel_max = 99; }


//	ShopBuyScrCurPosChg( wk, 1 );

	if( wk->shop_type == SHOP_TYPE_GOODS ||
		wk->shop_type == SHOP_TYPE_POKETHLON ||
		wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
//		ShopSubActVisible( wk, SHOP_MODE_SELECT_EX );
//		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT_EX;
//		return SHOP_SEQ_BUYNUM_WAIT;
		return ShopBuyCmpCheck( wk );

	}else{
		ShopSubActVisible( wk, SHOP_MODE_SELECT );
		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT;
	}

	return SHOP_SEQ_BUYSEL_WAIT;

}

//--------------------------------------------------------------------------------------------
/**
 * アイテム選択後のメッセージウェイト
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuySelWaitSeq( SHOP_WORK * wk )
{
	if( FldTalkMsgEndCheck( wk->midx ) == 0 ){
		return SHOP_SEQ_BUYSEL_WAIT;
	}
//	MyItemWinPut( wk );
//	NumSelWinPut( wk, 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], 0 );
	return SHOP_SEQ_BUYNUM_SEL;
}


//==============================================================================
/**
 * @brief   自分で所持しているどうぐの数を返す
 *
 * @param   wk
 * @param   item	所持している数を調べたいどうぐの管理NO
 *
 * @retval  int		所持しているどうぐの数
 */
//==============================================================================
int Shop_GetMyItemNum( SHOP_WORK *wk, int item )
{
	int num;
	if( wk->shop_type == SHOP_TYPE_ITEM ||
		wk->shop_type == SHOP_TYPE_GOODS ||
		wk->shop_type == SHOP_TYPE_POKETHLON ||
		wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
		// ぼんぐりの場合
		if( item>=ITEM_AKABONGURI && item<=ITEM_KUROBONGURI ){
			num = BonguriSave_GetBonguriNum( wk->bonguri, item-ITEM_AKABONGURI );
		}else{
			num = MyItem_GetItemNum( wk->myitem, wk->sel_item, HEAPID_WORLD );
		}
	}else if( wk->shop_type == SHOP_TYPE_SEAL ){
//		num = CB_SaveData_ItemNumGet( CB_SaveData_ItemDataGet(wk->myitem), wk->sel_item );
//		OS_Printf( "SEAL : id = %d, num = %d\n", wk->sel_item, num );
		num = CB_Tool_SealTotalNumGet( wk->myitem, wk->sel_item );
		OS_Printf( "SEAL : id = %d, num = %d\n", wk->sel_item, num );
	}else{
		num = 0;
	}

	return num;
}


#if 0
#define	MYITEM_BUFLEN	( 12*2 )
//--------------------------------------------------------------------------------------------
/**
 * 現在の所持数を表示するウィンドウを表示
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MyItemWinPut( SHOP_WORK * wk )
{
	STRBUF * expb;
	STRBUF * strb;
	u16	num;


	num = Shop_GetMyItemNum( wk, wk->sel_item );

	GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_MINE], 15 );
	BmpMenuWinWrite(
		&wk->win[WIN_IDX_MINE], WINDOW_TRANS_OFF, SHOP_MENU_WIN_CGX, MENU_WIN_PAL );

	expb = STRBUF_Create( MYITEM_BUFLEN, HEAPID_WORLD );
	strb = MSGMAN_AllocString( wk->mman, mes_shop_06_01 );
	WORDSET_RegisterNumber(
		wk->wset, 0, num, 3, NUMBER_DISPTYPE_SPACE, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, expb, strb );
	GF_STR_PrintSimple( &wk->win[WIN_IDX_MINE], FONT_SYSTEM, expb, 0, 0, MSG_NO_PUT, NULL );
	STRBUF_Delete( strb );
	STRBUF_Delete( expb );
	GF_BGL_BmpWinOnVReq( &wk->win[WIN_IDX_MINE] );
}
#endif

static u8 ShopBuyNumDecide( SHOP_WORK *wk )
{
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], 0 );
	BmpMenuWinClear( &wk->win[WIN_IDX_MINE], WINDOW_TRANS_OFF );
	BmpMenuWinClear( &wk->win[WIN_IDX_NUM],  WINDOW_TRANS_OFF );
	GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_TALK], 15 );
//	Snd_SePlay( FD_SHOP_SE_DECIDE );
	wk->sublcd_refresh = SUBLCD_REFRESH_PRICE_TALK;

//	GF_BGL_BmpWinOffVReq( &wk->win[WIN_CANCEL] );
//	GF_BGL_BmpWinOffVReq( &wk->win[WIN_CANCEL] );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_BUY], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_CANCEL], 0 );

	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_NUMUP10], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_NUMUP1], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_NUMDOWN10], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_NUMDOWN1], 0 );

	return ShopBuyCmpCheck( wk );

}

static u8 ShopBuyNumCancel( SHOP_WORK *wk )
{
	BmpMenuWinClear( &wk->win[WIN_IDX_MINE], WINDOW_TRANS_OFF );
	BmpMenuWinClear( &wk->win[WIN_IDX_NUM],  WINDOW_TRANS_OFF );
	BmpTalkWinClear( &wk->win[WIN_IDX_TALK], WINDOW_TRANS_ON );

	ShopBuyScrCurPosChg( wk, 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], wk->scr_draw[0] );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], wk->scr_draw[1] );
	ShopBuyCursorPalChg( wk, 0 );

//	Snd_SePlay( FD_SHOP_SE_CANCEL );

	ShopSubActVisible( wk, SHOP_MODE_LIST );
	wk->sublcd_refresh = SUBLCD_REFRESH_RELIST;

	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_S_CANCEL], 1 );

	return SHOP_SEQ_BUY_SELECT;

}
//--------------------------------------------------------------------------------------------
/**
 * 購入個数選択処理
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyNumSelSeq( SHOP_WORK * wk )
{
	if( NumSelectCheck( &wk->sel_num, wk->sel_max ) != APP_NUMSEL_NONE ){
//		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
		Snd_SePlay( SEQ_SE_DP_BAG_004 );
//		NumSelWinPut( wk, 1 );
		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT_NUM;
		return SHOP_SEQ_BUYNUM_SEL;
	}

	if( sys.trg & PAD_BUTTON_DECIDE ){
//		return ShopBuyNumDecide( wk );
		Snd_SePlay( FD_SHOP_SE_DECIDE );
		return ButtonAnmSet( wk, SHOP_CLA_S_BUY, SHOP_SEQ_BUYNUM_ENTER );
	}

	if( sys.trg & PAD_BUTTON_CANCEL ){
//		return ShopBuyNumCancel( wk );
//		Snd_SePlay( FD_SHOP_SE_CANCEL );
		Snd_SePlay( FD_SHOP_SE_CLOSE );
		return ButtonAnmSet( wk, SHOP_CLA_S_CANCEL, SHOP_SEQ_BUYNUM_CANCEL );
	}
	return SHOP_SEQ_BUYNUM_SEL;
}


//------------------------------------------------------------------
/**
 * @brief   購入数決定時のタッチ処理
 *
 * @param   wk
 * @param   arret
 *
 * @retval  u8		次のシーケンス
 */
//------------------------------------------------------------------
static u8 ShopBuyNumTouchSelSeq( SHOP_WORK *wk, u32 arret )
{
	switch(arret){
	//
	case 0:
		if( wk->sel_max < 10 ){ break; }
//		NumArroundCheck( &wk->sel_num, wk->sel_max,  10 );
		wk->sel_num = ItemNumMove( wk->sel_num, wk->sel_max, 10 );
//		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
		CLACT_AnmFrameSet( wk->cwp[SHOP_CLA_S_NUMUP10], 0 );
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_NUMUP10], 13 );
		Snd_SePlay( SEQ_SE_DP_BAG_004 );
		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT_NUM;
		break;
	case 1:
		if( wk->sel_max == 1 ){ break; }
//		NumArroundCheck( &wk->sel_num, wk->sel_max,   1 );
		wk->sel_num = ItemNumMove( wk->sel_num, wk->sel_max, 1 );
//		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
		CLACT_AnmFrameSet( wk->cwp[SHOP_CLA_S_NUMUP1], 0 );
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_NUMUP1], 13 );
		Snd_SePlay( SEQ_SE_DP_BAG_004 );
		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT_NUM;
		break;
	case 2:
		if( wk->sel_max < 10 ){ break; }
//		NumArroundCheck( &wk->sel_num, wk->sel_max, -10 );
		wk->sel_num = ItemNumMove( wk->sel_num, wk->sel_max, -10 );
//		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
		CLACT_AnmFrameSet( wk->cwp[SHOP_CLA_S_NUMDOWN10], 0 );
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_NUMDOWN10], 15 );
		Snd_SePlay( SEQ_SE_DP_BAG_004 );
		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT_NUM;
		break;
	case 3:
		if( wk->sel_max == 1 ){ break; }
//		NumArroundCheck( &wk->sel_num, wk->sel_max,   -1 );
		wk->sel_num = ItemNumMove( wk->sel_num, wk->sel_max, -1 );
//		Snd_SePlay( FD_SHOP_SE_CURSOR_MOVE );
		CLACT_AnmFrameSet( wk->cwp[SHOP_CLA_S_NUMDOWN1], 0 );
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_NUMDOWN1], 15 );
		Snd_SePlay( SEQ_SE_DP_BAG_004 );
		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT_NUM;
		break;
	case 4:
//		return ShopBuyNumDecide( wk );
		Snd_SePlay( FD_SHOP_SE_DECIDE );
		return ButtonAnmSet( wk, SHOP_CLA_S_BUY, SHOP_SEQ_BUYNUM_ENTER );

	case 5:
//		return ShopBuyNumCancel( wk );
//		Snd_SePlay( FD_SHOP_SE_CANCEL );
		Snd_SePlay( FD_SHOP_SE_CLOSE );
		return ButtonAnmSet( wk, SHOP_CLA_S_CANCEL, SHOP_SEQ_BUYNUM_CANCEL );
	}
	return SHOP_SEQ_BUYNUM_SEL;
}

//--------------------------------------------------------------------------------------------
/**
 * 選択した個数購入できるかチェック
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyCmpCheck( SHOP_WORK * wk )
{
	STRBUF * str;
	BOOL	check;

	if( wk->shop_type == SHOP_TYPE_ITEM ){
		check = MyItem_AddCheck( wk->myitem, wk->sel_item, wk->sel_num, HEAPID_WORLD );
	}else if( wk->shop_type == SHOP_TYPE_GOODS ){
        check = FALSE;
	}else if( wk->shop_type == SHOP_TYPE_POKETHLON || wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
		// ぼんぐりの場合
		if( wk->sel_item >= ITEM_AKABONGURI && wk->sel_item <= ITEM_KUROBONGURI ){
			if( BonguriSave_GetBonguriNum( wk->bonguri, wk->sel_item-ITEM_AKABONGURI ) == BONGURI_KEEP_MAX ){
				wk->sublcd_refresh = SUBLCD_REFRESH_CMP_FALSE_EX;
				return SHOP_SEQ_CANT_BUY_WAIT;
			}
		}else{
			if( MyItem_AddCheck( wk->myitem, wk->sel_item, wk->sel_num, HEAPID_WORLD ) == FALSE ){
				wk->sublcd_refresh = SUBLCD_REFRESH_CMP_FALSE_EX;
				return SHOP_SEQ_CANT_BUY_WAIT;
			}
		}
		ShopSubActVisible( wk, SHOP_MODE_SELECT_EX );
		wk->sublcd_refresh = SUBLCD_REFRESH_SELECT_EX;
		return SHOP_SEQ_BUYNUM_WAIT;
	}else{
		check = CB_SaveData_IsAddIt( wk->myitem, wk->sel_item, wk->sel_num );
	}

	// 買えなかった
	if( check == FALSE ){
		wk->sel_num = 0;
#if 0
		if( wk->shop_type == SHOP_TYPE_ITEM ){
			str = MSGMAN_AllocString( wk->mman, mes_shop_02_05 );
		}else if( wk->shop_type == SHOP_TYPE_GOODS ){
			str = MSGMAN_AllocString( wk->mman, mes_shop_03_02 );
		}else if( wk->shop_type == SHOP_TYPE_SEAL ){
			str = MSGMAN_AllocString( wk->mman, mes_shop_03_04 );
		}else if( wk->shop_type == SHOP_TYPE_POKETHLON ){
			str = MSGMAN_AllocString( wk->mman, mes_shop_03_05 );
		}else if( wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
			str = MSGMAN_AllocString( wk->mman, mes_shop_03_06 );
		}
		WORDSET_ExpandStr( wk->wset, wk->msgb, str );
		STRBUF_Delete( str );
		wk->midx = FieldTalkMsgStart( &wk->win[WIN_IDX_TALK], wk->msgb, wk->cfg, 1 );
#endif
		wk->sublcd_refresh = SUBLCD_REFRESH_CMP_FALSE;
		return SHOP_SEQ_BUYCMP_WAIT;
	}

	return SHOP_SEQ_BUYNUM_WAIT;
}



#if 0
#define	NUMSEL_BUFLEN	( 24 )
#define	NUMSEL_EX		( WIN_SHOP_NUM_SX * 8 )
//--------------------------------------------------------------------------------------------
/**
 * 個数選択ウィンドウ表示
 *
 * @param	wk		ショップワーク
 * @param	flg		ウィンドウ技表示フラグ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void NumSelWinPut( SHOP_WORK * wk, u8 flg )
{
	STRBUF * expb;
	STRBUF * strb;
	u32	siz;

	GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_NUM], 15 );

	if( flg == 0 ){
		BmpMenuWinWrite(
			&wk->win[WIN_IDX_NUM], WINDOW_TRANS_OFF, SHOP_MENU_WIN_CGX, MENU_WIN_PAL );
	}

	expb = STRBUF_Create( NUMSEL_BUFLEN, HEAPID_WORLD );
	strb = MSGMAN_AllocString( wk->mman, mes_shop_07_01 );
	WORDSET_RegisterNumber(
		wk->wset, 0, wk->sel_num, 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, expb, strb );
	GF_STR_PrintSimple(
		&wk->win[WIN_IDX_NUM], FONT_SYSTEM, expb, 0, 8, MSG_NO_PUT, NULL );
	STRBUF_Delete( strb );

	strb = MSGMAN_AllocString( wk->mman, mes_shop_07_02 );
	WORDSET_RegisterNumber(
		wk->wset, 0, wk->sel_price*wk->sel_num, 6,
		NUMBER_DISPTYPE_SPACE, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, expb, strb );
	siz = FontProc_GetPrintStrWidth( FONT_SYSTEM, expb, 0 );
	GF_STR_PrintSimple(
		&wk->win[WIN_IDX_NUM], FONT_SYSTEM, expb, NUMSEL_EX-siz, 8, MSG_NO_PUT, NULL );
	STRBUF_Delete( strb );
	STRBUF_Delete( expb );
	GF_BGL_BmpWinOnVReq( &wk->win[WIN_IDX_NUM] );
}
#endif

//--------------------------------------------------------------------------------------------
/**
 * 購入個数選択後のメッセージウェイト
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyNumWaitSeq( SHOP_WORK * wk )
{
	if( FldTalkMsgEndCheck( wk->midx ) == 0 ){
		return SHOP_SEQ_BUYNUM_WAIT;
	}
//	wk->mw = BmpYesNoSelectInit(
//				wk->bgl, &ShopBuyYesNoBmpWin, SHOP_MENU_WIN_CGX, MENU_WIN_PAL, HEAPID_WORLD );

	wk->sublcd_refresh = SUBLCD_REFRESH_BUY_YESNO;
	return SHOP_SEQ_BUY_YESNO;
}

//--------------------------------------------------------------------------------------------
/**
 * 買いますか？はい・いいえ処理
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyYesNoSeq( SHOP_WORK * wk, u32 arret )
{
//	switch( BmpYesNoSelectMain( wk->mw, HEAPID_WORLD ) ){
	switch( arret ){
	case 0:
		wk->sublcd_refresh = SUBLCD_REFRESH_BUY_MESSAGE;
//		Snd_SePlay( SEQ_SE_DP_REGI );
		return SHOP_SEQ_BUY_CMP;

	case 1:
//	case BMPMENU_CANCEL:
		BmpTalkWinClear( &wk->win[WIN_IDX_TALK], WINDOW_TRANS_ON );
		ShopBuyScrCurPosChg( wk, 0 );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], wk->scr_draw[0] );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], wk->scr_draw[1] );
		ShopBuyCursorPalChg( wk, 0 );
		ShopSubActVisible( wk, SHOP_MODE_LIST );
		wk->sublcd_refresh = SUBLCD_REFRESH_RELIST;

		return SHOP_SEQ_BUY_SELECT;
	}
	return SHOP_SEQ_BUY_YESNO;
}


//------------------------------------------------------------------
/**
 * @brief   所持金・ポケスロンポイントから購入分引く
 *
 * @param   wk
 * @param   price
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void _sub_gold_point( SHOP_WORK *wk, int price )
{
	if(wk->shop_type==SHOP_TYPE_POKETHLON || wk->shop_type==SHOP_TYPE_POKETHLON_CARD){
		PkthlnSv_SubThlnPoint ( wk->pokethlon_save, price );
	}else{
		Mystatus_SubGold( wk->my, wk->sel_price*wk->sel_num );
	}
}

// ポケスロンショップでは一つしか買えない
#define POKETHLON_SHOP_BUY_NUM		( 1 )

//------------------------------------------------------------------
/**
 * @brief   ポケスロンショップで購入した時に対応したものを増やす
 *
 * @param   wk
 * @param   item	ぼんぐりだったり、どうぐだったりする
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void _add_pokethlon_shop( SHOP_WORK *wk, int item )
{
	// ぼんぐりの場合
	if(item>=ITEM_AKABONGURI && item<=ITEM_KUROBONGURI){
		BonguriSave_BonguriAdd( wk->bonguri, item-ITEM_AKABONGURI, POKETHLON_SHOP_BUY_NUM );
	}else{
	// 通常アイテムの場合
		MyItem_AddItem( wk->myitem, wk->sel_item, POKETHLON_SHOP_BUY_NUM, HEAPID_WORLD );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 購入後のメッセージウェイト処理１
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyCmpSeq( SHOP_WORK * wk )
{
	if( FldTalkMsgEndCheck( wk->midx ) == 0 ){
		return SHOP_SEQ_BUY_CMP;
	}

	if( wk->shop_type == SHOP_TYPE_ITEM ){
		MyItem_AddItem( wk->myitem, wk->sel_item, wk->sel_num, HEAPID_WORLD );
	}else if( wk->shop_type == SHOP_TYPE_POKETHLON ){
		_add_pokethlon_shop( wk, wk->sel_item );
		PkthlnSv_SetShopFlag ( wk->pokethlon_save, wk->cursor_pos+wk->scr );
	}else if( wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
		// カード登録
		PkthlnSv_SetRankingAppear ( wk->pokethlon_save, wk->sel_item-ITEM_DEETAKAADO01 );
	}else{
		CB_SaveData_ItemNumAddCheck( wk->myitem, wk->sel_item, wk->sel_num );
	}

	// 購入金額・ポイント分引く
	_sub_gold_point( wk, wk->sel_price*wk->sel_num );
	RECORD_Add( wk->rec, RECID_SHOPPING_MONEY, wk->sel_price*wk->sel_num );
//	ShopBuyGoldWinPut( wk, 1 );

	return SHOP_SEQ_BUYCMP_WAIT;
}

//--------------------------------------------------------------------------------------------
/**
 * 購入後のメッセージウェイト処理２
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyCmpWaitSeq( SHOP_WORK * wk )
{
	if( FldTalkMsgEndCheck( wk->midx ) == 0 ){
		return SHOP_SEQ_BUYCMP_WAIT;
	}
	if( sys.trg & (PAD_BUTTON_A|PAD_BUTTON_B) || sys.tp_trg){

		if( wk->dp_flg == TRUE ){
			SysWork_RegularCountPlus( wk->evwk );
		}

#ifdef SHOP_PREMIUM_BALL
		if( wk->shop_type == SHOP_TYPE_ITEM &&
			wk->sel_item == ITEM_MONSUTAABOORU && wk->sel_num >= 10 ){
			if( MyItem_AddItem( wk->myitem, ITEM_PUREMIABOORU, 1, HEAPID_WORLD ) == TRUE ){
				wk->sublcd_refresh = SUBLCD_REFRESH_PREMIUM_MESSAGE;
				RECORD_Inc( wk->rec, RECID_PREMIUM_BALL );
#if 0
				STRBUF * str = MSGMAN_AllocString( wk->mman, mes_shop_02_08 );
				WORDSET_ExpandStr( wk->wset, wk->msgb, str );
				STRBUF_Delete( str );
				GF_BGL_BmpWinDataFill( &wk->win[WIN_IDX_TALK], 15 );
				wk->midx = FieldTalkMsgStart( &wk->win[WIN_IDX_TALK], wk->msgb, wk->cfg, 1 );
#endif
				return SHOP_SEQ_BUYOMAKE_WAIT;
			}
		}
#endif
		BmpTalkWinClear( &wk->win[WIN_IDX_TALK], WINDOW_TRANS_ON );

		ShopBuyScrCurPosChg( wk, 0 );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], wk->scr_draw[0] );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], wk->scr_draw[1] );
		ShopBuyCursorPalChg( wk, 0 );
		ShopSubActVisible( wk, SHOP_MODE_LIST );
		wk->sublcd_refresh = SUBLCD_REFRESH_RELIST;

		return SHOP_SEQ_BUY_SELECT_RETURN;
	}
	return SHOP_SEQ_BUYCMP_WAIT;
}


//------------------------------------------------------------------
/**
 * @brief   最初のどうぐ選択の時点でお金が足りなかった時のメッセージ待ち
 *
 * @param   wk
 *
 * @retval  u8		次のシーケンス
 */
//------------------------------------------------------------------
static u8 ShopBuyCantWaitSeq( SHOP_WORK * wk )
{
	// メッセージ表示待ち
	if( FldTalkMsgEndCheck( wk->midx ) == 0 ){
		return SHOP_SEQ_CANT_BUY_WAIT;
	}

	// 会話終了後キーorタッチ待ち
	if( sys.trg & (PAD_BUTTON_A|PAD_BUTTON_B) || sys.tp_trg){

		// リスト画面再描画処理（どうぐの個数選択まで行ってないのでリスト再描画ですむ）
		BmpTalkWinClear( &wk->win[WIN_IDX_TALK], WINDOW_TRANS_ON );

		ShopBuyScrCurPosChg( wk, 0 );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], wk->scr_draw[0] );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], wk->scr_draw[1] );
		ShopBuyCursorPalChg( wk, 0 );
		ShopSubActVisible( wk, SHOP_MODE_LIST );

		wk->sublcd_refresh = SUBLCD_REFRESH_LIST_ONLY;

		return SHOP_SEQ_BUY_SELECT_RETURN;
	}

	return SHOP_SEQ_CANT_BUY_WAIT;
}

//--------------------------------------------------------------------------------------------
/**
 * プレミアボール入手後のメッセージウェイト
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyOmakeWait( SHOP_WORK * wk )
{
	if( FldTalkMsgEndCheck( wk->midx ) == 0 ){
		return SHOP_SEQ_BUYOMAKE_WAIT;
	}
	if( sys.trg & (PAD_BUTTON_A|PAD_BUTTON_B) || sys.tp_trg ){
		BmpTalkWinClear( &wk->win[WIN_IDX_TALK], WINDOW_TRANS_ON );

		ShopBuyScrCurPosChg( wk, 0 );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], wk->scr_draw[0] );
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], wk->scr_draw[1] );
		ShopBuyCursorPalChg( wk, 0 );
		ShopSubActVisible( wk, SHOP_MODE_LIST );
		wk->sublcd_refresh = SUBLCD_REFRESH_RELIST;

		return SHOP_SEQ_BUY_SELECT;
	}
	return SHOP_SEQ_BUYOMAKE_WAIT;
}


static  int _psitem_price_get( u16 item, const PS_SHOP_DATA *psitem, int max );

//------------------------------------------------------------------
/**
 * @brief   ポケスロンアイテムリストから値段を取得
 *
 * @param   item
 * @param   psitem
 * @param   max
 *
 * @retval  int
 */
//------------------------------------------------------------------
static int _psitem_price_get( u16 item, const PS_SHOP_DATA *psitem, int max )
{
	int i;
	for(i=0;i<max;i++){
		if(item==psitem[i].item){
			return psitem[i].point;
		}
	}

	// ここに来たらダメ（アイテムリストと選択アイテムが一致していない）
	GF_ASSERT(0);
	return 0;
}


//--------------------------------------------------------------------------------------------
/**
 * アイテムの値段取得
 *
 * @param	wk		ショップワーク
 * @param	item	アイテムID
 *
 * @return	値段
 */
//--------------------------------------------------------------------------------------------
u32 ShopBuyItemPriceGet( SHOP_WORK * wk, u16 item )
{
	if( wk->shop_type == SHOP_TYPE_ITEM ){
		return ItemParamGet( item, ITEM_PRM_PRICE, HEAPID_WORLD );
	}else if( wk->shop_type == SHOP_TYPE_GOODS ){
		return 100;
//		return GOODS_GetGoodsMoney( (const int)item );
	}else if( wk->shop_type == SHOP_TYPE_POKETHLON || wk->shop_type == SHOP_TYPE_POKETHLON_CARD ){
		return _psitem_price_get( item, wk->psitem, wk->max);
	}
	return 100;
}

#if 0
{

	if( wk->shop_type == SHOP_TYPE_ITEM ){
		return ItemParamGet( item, ITEM_PRM_PRICE, HEAPID_WORLD );
	}else if( wk->shop_type == SHOP_TYPE_GOODS ){
		return GOODS_GetGoodsMoney( (const int)item );
	}
	return Seal_PriceGet( (u8)item );
}
#endif

//------------------------------------------------------------------
/**
 * @brief   ショップ購入下画面終了切り替え
 *
 * @param   fsys
 * @param   wk
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void ShopBuySublcdEnd(FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
	FieldSubLcdControler_ChangeApp( fsys, fsys->submenu_app, NULL );

}

//--------------------------------------------------------------------------------------------
/**
 * 購入処理終了スクロール
 *
 * @param	fsys	フィールドワーク
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopBuyEndSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
#ifndef NO_SHOP_SCROLL
	// ショップ画面スクロール無し
	if( wk->cm_cnt != wk->cm_max ){
		VecFx32 move = {-8*FX32_ONE,0,0};
		GFC_ShiftCamera( &move, wk->camera );
		wk->cm_cnt++;
		return SHOP_SEQ_BUY_END;
	}
#endif
	if(FieldSubLcdControler_GetSequence(fsys)==SUBLCD_MODE_FIELD_MENU){
//		if(FieldSubLcdControler_GetNowApp(fsys)==SUBLCD_SEQ_MAIN){
		if(FieldSubLcdControler_GetNowApp(fsys)!=SUBLCD_SEQ_MAIN){
			return SHOP_SEQ_BUY_END;
		}
	}


	wk->cm_cnt = 0;
	GFC_CopyCamera( wk->camera, fsys->camera_ptr );		// カメラ反映
	GFC_FreeCamera( wk->camera);						// カメラ削除
	GFC_AttachCamera( fsys->camera_ptr );				// カメラアタッチ
//	ShopMenuSet( wk );

	ShopBuyActExit( wk );
/*
	FldTalkBmpAdd( fsys->bgl, &wk->win[WIN_IDX_FLDTALK], FLD_MBGFRM_FONT );
	FieldTalkWinPut( &wk->win[WIN_IDX_FLDTALK], wk->cfg );
	{
		STRBUF * str = MSGMAN_AllocString( wk->mman, mes_shop_01_03 );
		WORDSET_ExpandStr( wk->wset, wk->msgb, str );
		STRBUF_Delete( str );
	}
	wk->midx = FieldTalkMsgStart( &wk->win[WIN_IDX_FLDTALK], wk->msgb, wk->cfg, 1 );

//	FieldSubLcdControler_ChangeApp( fsys, SUBLCD_MODE_FIELD_MENU, NULL );

	return SHOP_SEQ_MENU_RET;
*/

	return SHOP_SEQ_END;
}

//--------------------------------------------------------------------------------------------
/**
 * ショップメニューへ戻る
 *
 * @param	wk		ショップワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
/*
static u8 ShopBuyMenuRetSeq( SHOP_WORK * wk )
{
	if( FldTalkMsgEndCheck( wk->midx ) == 0 ){
		return SHOP_SEQ_MENU_RET;
	}
	GF_BGL_BmpWinDel( &wk->win[WIN_IDX_FLDTALK] );
	ShopMenuSet( wk );
	return SHOP_SEQ_MENU;
}
*/



//--------------------------------------------------------------------------------------------
/**
 * ショップ終了メッセージセット
 *
 * @param	fsys	フィールドワーク
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
/*
static void ShopExitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
	STRBUF * str = MSGMAN_AllocString( wk->mman, mes_shop_01_02 );
	WORDSET_ExpandStr( wk->wset, wk->msgb, str );
	STRBUF_Delete( str );
	FldTalkBmpAdd( fsys->bgl, &wk->win[WIN_IDX_FLDTALK], FLD_MBGFRM_FONT );
	FieldTalkWinPut( &wk->win[WIN_IDX_FLDTALK], wk->cfg );
	wk->midx = FieldTalkMsgStart( &wk->win[WIN_IDX_FLDTALK], wk->msgb, wk->cfg, 1 );
}
*/






//--------------------------------------------------------------------------------------------
/**
 * 購入画面のセルアクターセット
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ShopBuyActSet( SHOP_WORK * wk )
{
	u32	i;

	FieldCellActSet( &wk->fcat, &CatsFileList, SHOP_CLA_MAX, HEAPID_WORLD );

	for( i=0; i<SHOP_CLA_MAX; i++ ){
		wk->cwp[i] = FieldCellActAdd( &wk->fcat, &ActAddParam[i] );
	}

	// BGとのプライオリティを下げる
	CLACT_BGPriorityChg( wk->cwp[SHOP_CLA_S_CANCEL], 1 );
	CLACT_BGPriorityChg( wk->cwp[SHOP_CLA_S_BUY], 1 );

	// カーソルはオートアニメする
	CLACT_SetAnmFlag( wk->cwp[SHOP_CLA_S_CURSOR], 1 );

	// 上画面のOAMを隠す
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_CURSOR], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_U], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ARROW_D], 0 );
	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ITEMICON], 0 );

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );

	// 表示制御を初期状態に
	ShopSubActVisible( wk, SHOP_MODE_LIST );

	ShopCursorActPosSet( wk, wk->cursor_pos, SHOP_MODE_LIST );

	ShopItemIconPageChange( wk, wk->scr, wk->max );
}

//--------------------------------------------------------------------------------------------
/**
 * 購入画面のセルアクター削除
 *
 * @param	wk		ショップワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyActExit( SHOP_WORK * wk )
{
	u32	i;

	for( i=0; i<SHOP_CLA_MAX; i++ ){
		CLACT_Delete( wk->cwp[i] );
		wk->cwp[i] = NULL;
	}
	FieldCellActDelete( &wk->fcat );
	wk->fcat.cas = NULL;
}

// セルアクターの状態を判定させるためのテーブル
// アクター番号　モード　判定
static u8 visible_table[][3]={
	{ 	SHOP_CLA_S_ITEMICON0,	5,	2, },
	{ 	SHOP_CLA_S_ITEMICON1,	5,	2, },
	{ 	SHOP_CLA_S_ITEMICON2,	5,	2, },
	{ 	SHOP_CLA_S_ITEMICON3,	5,	2, },
	{ 	SHOP_CLA_S_ITEMICON4,	5,	2, },
	{ 	SHOP_CLA_S_ITEMICON5,	5,	2, },

	{ 	SHOP_CLA_S_CURSOR,		1,	0, },
	{ 	SHOP_CLA_S_PAGEDOWN,	3,	0, },
	{ 	SHOP_CLA_S_PAGEUP,		4,	0, },

	{ 	SHOP_CLA_S_CANCEL,		1,	1, },

	{ 	SHOP_CLA_S_NUMUP10,		0,	1, },
	{ 	SHOP_CLA_S_NUMUP1,		0,	1, },
	{ 	SHOP_CLA_S_NUMDOWN10,	0,	1, },
	{ 	SHOP_CLA_S_NUMDOWN1,	0,	1, },
	{ 	SHOP_CLA_S_BUY,			0,	1, },

};



//==============================================================================
/**
 * @brief   ショップの状態に合わせてアクターの表示状態を制御する
 *
 * @param   wk
 * @param   mode	SHOP_MODE_LIST か SHOP_MODE_SELECT
 *
 * @retval  none
 */
//==============================================================================
void ShopSubActVisible( SHOP_WORK *wk, int mode )
{
	int i;
	switch(mode){
	// どうぐリスト時
	case SHOP_MODE_LIST:

		// どうぐアイコンを初期位置に戻す
		for(i=0;i<SHOP_PAGE_ITEM_NUM;i++){
			VecFx32 mat;
			mat.x = ActAddParam[SHOP_CLA_S_ITEMICON0+i].x << FX32_SHIFT;
			mat.y = (ActAddParam[SHOP_CLA_S_ITEMICON0+i].y << FX32_SHIFT) +SUB_SURFACE_Y;;
			mat.z = ActAddParam[SHOP_CLA_S_ITEMICON0+i].z << FX32_SHIFT;
			CLACT_SetMatrix( wk->cwp[SHOP_CLA_S_ITEMICON0+i], &mat);
		}

		for(i=0;i<NELEMS(visible_table);i++){
			// 下矢印用処理
			if(visible_table[i][1]==4){
				if(wk->scr+6 < wk->max){
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 1 );
				}else{
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 0 );
				}
			// 上矢印用処理
			}else if(visible_table[i][1]==3){
				if(wk->scr==0){
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 0 );
				}else{
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 1 );
				}
			}else if(visible_table[i][1]==5){
				if(wk->scr+i<wk->max){
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 1 );
				}else{
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 0 );
				}
			}else{
				CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], visible_table[i][1] );
			}
		}
		CLACT_AnmFrameSet( wk->cwp[SHOP_CLA_S_CANCEL], 0 );
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_CANCEL], 6 );
		break;

	// どうぐ選択時
	case SHOP_MODE_SELECT:
		for(i=0;i<NELEMS(visible_table);i++){
			if(visible_table[i][2]==2){
				if(wk->cursor_pos == i){
					// 選択されたどうぐアイコンは中央へ移動
					VecFx32 mat;
					mat.x = SELECT_ITEM_ICON_POS_X << FX32_SHIFT;
					mat.y = (SELECT_ITEM_ICON_POS_Y << FX32_SHIFT) +SUB_SURFACE_Y;
					mat.z = 0 << FX32_SHIFT;
					CLACT_SetMatrix( wk->cwp[visible_table[i][0]], &mat);
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 1 );
				}else{
					// 選択されてないどうぐは隠す
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 0 );
				}
			}else{
				if( visible_table[i][0] == SHOP_CLA_S_NUMUP10 ||
					visible_table[i][0] == SHOP_CLA_S_NUMDOWN10 ){
					if( wk->sel_max < 10 ){
						CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 0 );
					}else{
						CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 1 );
					}
				}else if( visible_table[i][0] == SHOP_CLA_S_NUMUP1 ||
						  visible_table[i][0] == SHOP_CLA_S_NUMDOWN1 ){
					if( wk->sel_max == 1 ){
						CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 0 );
					}else{
						CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 1 );
					}
				}else{
					CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], visible_table[i][2] );
				}
			}
		}
		CLACT_AnmFrameSet( wk->cwp[SHOP_CLA_S_CANCEL], 0 );
		CLACT_AnmChg( wk->cwp[SHOP_CLA_S_CANCEL], 26 );
		break;

	// どうぐ選択時（個数選択なし
	case SHOP_MODE_SELECT_EX:
		for(i=0;i<NELEMS(visible_table);i++){
			if(wk->cursor_pos == i){
				// 選択されたどうぐアイコンは中央へ移動
				VecFx32 mat;
				mat.x = SELECT_ITEM_ICON_POS_X << FX32_SHIFT;
				mat.y = (SELECT_ITEM_ICON_POS_Y << FX32_SHIFT) +SUB_SURFACE_Y;
				mat.z = 0 << FX32_SHIFT;
				CLACT_SetMatrix( wk->cwp[visible_table[i][0]], &mat);
				CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 1 );
			}else{
				CLACT_SetDrawFlag( wk->cwp[visible_table[i][0]], 0 );
			}
		}
		break;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 購入画面のスクロール矢印の位置をセット
 *
 * @param	wk		ショップワーク
 * @param	flg		0 = アイテム選択, 1 = 個数選択
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyScrCurPosChg( SHOP_WORK * wk, u8 flg )
{
	if( flg == 0 ){
		CATS_ObjectPosSet( wk->cwp[SHOP_CLA_ARROW_U], LIST_SCR_PX, LIST_SCR_U_PY );
		CATS_ObjectPosSet( wk->cwp[SHOP_CLA_ARROW_D], LIST_SCR_PX, LIST_SCR_D_PY );
	}else{
		CATS_ObjectPosSet( wk->cwp[SHOP_CLA_ARROW_U], NUM_SCR_PX, NUM_SCR_U_PY );
		CATS_ObjectPosSet( wk->cwp[SHOP_CLA_ARROW_D], NUM_SCR_PX, NUM_SCR_D_PY );
	}
}



//--------------------------------------------------------------------------------------------
/**
 * 購入画面のアイテムアイコン切り替え
 *
 * @param	wk		 	ショップワーク
 * @param	item		アイテムID
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyItemIconChg( SHOP_WORK * wk, u16 item )
{
	CLACT_U_RES_OBJ_PTR	obj;

	if( wk->shop_type != SHOP_TYPE_ITEM &&
		wk->shop_type != SHOP_TYPE_POKETHLON &&
		wk->shop_type != SHOP_TYPE_POKETHLON_CARD ){
		CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ITEMICON], 0 );
		return;
	}

	// キャラ
	obj = CLACT_U_ResManagerGetIDResObjPtr( wk->fcat.resMan[0], 2 );
	CLACT_U_ResManagerResChgArcChar(
		wk->fcat.resMan[0], obj,
		ARC_ITEMICON, GetItemIndex(item,ITEM_GET_ICON_CGX), 0, HEAPID_WORLD );
	CLACT_U_CharManagerReTrans( obj );

	// パレット
	obj = CLACT_U_ResManagerGetIDResObjPtr( wk->fcat.resMan[1], 1 );
	CLACT_U_ResManagerResChgArcPltt(
		wk->fcat.resMan[1], obj,
		ARC_ITEMICON, GetItemIndex(item,ITEM_GET_ICON_PAL), 0, HEAPID_WORLD );
	CLACT_U_PlttManagerReTrans( obj );

	CLACT_SetDrawFlag( wk->cwp[SHOP_CLA_ITEMICON], 1 );
}


//--------------------------------------------------------------------------------------------
/**
 * 購入画面のアイテムアイコン切り替え
 *
 * @param	wk		 	ショップワーク
 * @param	item		アイテムID
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuySubLCDItemIconChg( SHOP_WORK * wk, int charaId, int palId,  u16 item )
{
	CLACT_U_RES_OBJ_PTR	obj;

	// キャラ
	obj = CLACT_U_ResManagerGetIDResObjPtr( wk->fcat.resMan[0], charaId );
	CLACT_U_ResManagerResChgArcChar(
		wk->fcat.resMan[0], obj,
		ARC_ITEMICON, GetItemIndex(item,ITEM_GET_ICON_CGX), 0, HEAPID_WORLD );
	CLACT_U_CharManagerReTrans( obj );

	// パレット
	MORI_PRINT ("paladr = %08x\n", CLACT_U_ResManagerGetIDResObjPtr( wk->fcat.resMan[1], palId ));
	obj = CLACT_U_ResManagerGetIDResObjPtr( wk->fcat.resMan[1], palId );
	CLACT_U_ResManagerResChgArcPltt(
		wk->fcat.resMan[1], obj,
		ARC_ITEMICON, GetItemIndex(item,ITEM_GET_ICON_PAL), 0, HEAPID_WORLD );
	CLACT_U_PlttManagerReTrans( obj );
}

//--------------------------------------------------------------------------------------------
/**
 * 購入画面のアイテム選択カーソルのパレット変更
 *
 * @param	wk		ショップワーク
 * @param	num		パレット番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopBuyCursorPalChg( SHOP_WORK * wk, u8 num )
{
	CATS_ObjectPaletteSet( wk->cwp[SHOP_CLA_CURSOR], num );
}



//============================================================================================
//============================================================================================

static u8 ButtonAnmSet( SHOP_WORK * wk, u8 id, u8 next )
{
	SHOP_BUTTON_ANM_WORK * bawk = &wk->button_anm_work;

	bawk->id   = id;
	bawk->seq  = 0;
	bawk->cnt  = 0;
	bawk->next = next;

	return SHOP_SEQ_BUY_BUTTON_ANM;
}

static u8 ButtonAnmMain( SHOP_WORK * wk )
{
	SHOP_BUTTON_ANM_WORK * bawk = &wk->button_anm_work;

	switch( bawk->seq ){
	case 0:
		CATS_ObjectPaletteSet( wk->cwp[bawk->id], 7 );
		bawk->seq++;
		break;

	case 1:
		bawk->cnt++;
		if( bawk->cnt != 4 ){ break; }
		CATS_ObjectPaletteSet( wk->cwp[bawk->id], 6 );
		bawk->cnt = 0;
		bawk->seq++;
		break;

	case 2:
		bawk->cnt++;
		if( bawk->cnt == 2 ){
			return bawk->next;
		}
	}

	return SHOP_SEQ_BUY_BUTTON_ANM;
}





//============================================================================================
//	売る
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * フェードアウトセット ( -> バッグ画面へ )
 *
 * @param	wk		ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ShopSaleInitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
	FieldFadeWipeSet( FLD_DISP_BRIGHT_BLACKOUT );
	wk->seq = SHOP_SEQ_SALE_CALL;
}

//--------------------------------------------------------------------------------------------
/**
 * バッグ画面呼び出し
 *
 * @param	fsys	フィールドワーク
 * @param	wk		ショップワーク
 *
 * @return	移行するシーケンス
 */
//--------------------------------------------------------------------------------------------
static void ShopSaleCallSeq( GMEVENT_CONTROL * event )
{
	FIELDSYS_WORK * fsys;
	SHOP_WORK * wk;

	if( WIPE_SYS_EndCheck() == FALSE ){ return; }

	fsys = FieldEvent_GetFieldSysWork(event);
	wk = FieldEvent_GetSpecialWork(event);

//	ShopMenuExit( wk );

	{
		MYITEM * myitem;

		myitem = SaveData_GetMyItem( fsys->savedata );
		wk->bag_wk = MyItem_MakeBagData( myitem, BagList, HEAPID_WORLD );
		BAG_SysDataSet( wk->bag_wk, fsys->savedata, BAG_MODE_ITEMSALE,
						fsys->bag_cursor, &fsys->KeyTouchStatus );
	}

	FieldBag_SubProcSet( fsys, wk->bag_wk );

	FieldEvent_Change( event, GMEVENT_ShopSale, wk );
	wk->seq = SHOP_SEQ_SALE_WAIT;
}

//--------------------------------------------------------------------------------------------
/**
 * バッグ画面終了待ち
 *
 * @param	fsys	フィールドワーク
 * @param	wk		ショップワーク
 *
 * @return	移行するシーケンス
 */
//--------------------------------------------------------------------------------------------
/*
static u8 ShopSaleWaitSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
	// サブプロセス終了待ち
	if( FieldEvent_Cmd_WaitSubProcEnd( fsys ) ) {
		return SHOP_SEQ_SALE_WAIT;
	}

	wk->fnote_sale_cnt = BagSysSaleCntGet( wk->bag_wk );

	sys_FreeMemoryEz( wk->bag_wk );

	FieldEvent_Cmd_SetMapProc( fsys );

	return SHOP_SEQ_SALE_RET;
}
*/

//--------------------------------------------------------------------------------------------
/**
 * ショップ復帰待ち
 *
 * @param	fsys	フィールドワーク
 *
 * @return	移行するシーケンス
 */
//--------------------------------------------------------------------------------------------
/*
static u8 ShopSaleRetSeq( FIELDSYS_WORK * fsys )
{
	// フィールドマッププロセス開始待ち
	if( FieldEvent_Cmd_WaitMapProcStart(fsys) ){
//		FieldOBJSys_MoveStopAll( fsys->fldobjsys );
		FieldFadeWipeSet( FLD_DISP_BRIGHT_BLACKIN );
		return SHOP_SEQ_SALE_MENU_RET;
	}
	return SHOP_SEQ_SALE_RET;
}
*/

//--------------------------------------------------------------------------------------------
/**
 * 復帰フェード待ち
 *
 * @param	fsys	フィールドワーク
 * @param	wk		ショップワーク
 *
 * @return	移行するシーケンス
 */
//--------------------------------------------------------------------------------------------
static u8 ShopSaleMenuRetSeq( FIELDSYS_WORK * fsys, SHOP_WORK * wk )
{
	if( WIPE_SYS_EndCheck() == FALSE ){
		return SHOP_SEQ_SALE_MENU_RET;
	}

/*
	FldTalkBmpAdd( fsys->bgl, &wk->win[WIN_IDX_FLDTALK], FLD_MBGFRM_FONT );
	FieldTalkWinPut( &wk->win[WIN_IDX_FLDTALK], wk->cfg );
	{
		STRBUF * str = MSGMAN_AllocString( wk->mman, mes_shop_01_03 );
		WORDSET_ExpandStr( wk->wset, wk->msgb, str );
		STRBUF_Delete( str );
	}
	wk->midx = FieldTalkMsgStart( &wk->win[WIN_IDX_FLDTALK], wk->msgb, wk->cfg, 1 );
	return SHOP_SEQ_MENU_RET;
*/

	return SHOP_SEQ_END;
}


//------------------------------------------------------------------
/**
 * @brief   どうぐの数と最大数の範囲で数を増減させる
 *
 * @param   num		現在の数
 * @param   max		最大数
 * @param   move	変動させる数（-100〜100）
 *
 * @retval  static
 */
//------------------------------------------------------------------
static int ItemNumMove( int num, int max, int move )
{
	if(move>0){
		// プラスのとき
		if(num==max){
			num = 1;
		}else{
			num += move;
			if(num>max){
				num = max;
			}
		}
	}else{
		// マイナスのとき
		if(num==1){
			num = max;
		}else{
			num += move;
			if(num<=0){
				num = 1;
			}
		}
	}

	return num;
}